clear
input str20 cntry str30 outcome lb icc ub
"Finland" "Attainment" .35 .36 .38
"Germany" "Attainment" .43 .51 .60
"Norway" "Attainment" .41 .41 .42
"Sweden" "Attainment" .41 .41 .42
"United Kingdom" "Attainment" .34 .44 .54
"United States" "Attainment" .49 .51 .53
"Finland" "GPA" . . .
"Germany" "GPA" .19 .23 .28
"Norway" "GPA" .48 .48 .48
"Sweden" "GPA" .52 .52 .52
"United Kingdom" "GPA" . . .
"United States" "GPA" .37 .41 .46
"Finland" "Cognitive skills" . . .
"Germany" "Cognitive skills" .39 .46 .52
"Norway" "Cognitive skills" . . .
"Sweden" "Cognitive skills" .50 .50 .51
"United Kingdom" "Cognitive skills" . . .
"United States" "Cognitive skills" .55 .57 .60
end
// Defining the label first allows to determine order of -encode- categories
label define country 1 "Finland" 2 "Germany" 3 "Norway" 4 "Sweden" ///
5 "United Kingdom" 6 "United States"
encode cntry, gen(country) label(country)
twoway (rcap icc icc country, by(outcome, note("") row(1) legend(off)) horizontal) ///
(rspike ub lb country, by(outcome) horizontal) ///
, ylabel(1/6, val) ytitle("") xscale(alt) yscale(reverse)
Showing posts with label encode. Show all posts
Showing posts with label encode. Show all posts
Mar 28, 2016
Random graphs (67): Dot plots with confidence intervals
Labels:
encode,
Random graphs,
twoway rcap,
twoway rspike
May 21, 2015
Random graphs (47): Complex scatterplot
import excel "C:\table+graph field match countries.xlsx", sheet("Sheet2") cellrange(A1:I27) clear firstrow
renvars, lower // Switch variable names to lower case
list // Check data
// Bring variable names into systematic shape
foreach x of varlist healthwelfare education socialsciencesbusinesslaw ///
artshumanities services sciencemathcomputing ///
agricultureveterinary engineeringmanufacturing {
ren `x' var_`x'
}
list // Check data
// Reshape data
reshape long var_, i(country) j(field_str) string
// Convert proportion into percentage
replace var_ = var_ * 100
// Get field_str variable into numerical format
encode field_str, gen(field1)
label define field1 1 "Agriculture and Veterinary" ///
2 "Arts and Humanities" ///
3 "Education" ///
4 "Engineering and Manufacturing" ///
5 "Health and Welfare" ///
6 "Science, Math, and Computing" ///
7 "Services" ///
8 "Social Sciences, Business, and Law", modify
// Sort by average segregation per field
list field1 var if country == "EU average"
recode field1 (5 = 1 "Health and Welfare") ///
(3 = 2 "Education") ///
(8 = 3 "Social Sciences, Business, and Law") ///
(2 = 4 "Arts and Humanities") ///
(7 = 5 "Services") ///
(6 = 6 "Science, Math, and Computing") ///
(1 = 7 "Agriculture and Veterinary") ///
(4 = 8 "Engineering and Manufacturing") ///
, gen(field)
// Plot
sort field var_
twoway (scatter field var_ if country != "EU average") ///
(scatter field var_ if country == "EU average", connect(l) lwidth(thick)) ///
, ylabel(1/8, val) xscale(alt) ///
xtitle("Percentage women by field of study" "in European countries") ///
ytitle("") note(" " "{it:Source:} European Labor Force Survey 2011, own calculations.", span) ///
legend(order(2) label(2 "Average" "across" "countries") ring(0) pos(1))
Mar 18, 2013
Random graphs (8): Coefficient plot by hand
While the result certainly looks cool, such a graph can be extremely tedious to make.
// Requires parmest, ingap, and eclplot
use eulfsahm2010, clear
// Create and label dummy variables for regression model
fre age
quietly tab age, gen(age)
label var age1 "15-19 years"
label var age2 "20-24 years"
label var age3 "25-29 years"
label var age4 "30-34 years"
label var age5 "35-39 years"
label var age6 "40-44 years"
label var age7 "45-49 years"
label var age8 "50-54 years"
label var age9 "55-59 years"
label var age10 "60-64 years"
fre marstat
quietly tab marstat, gen(marstat)
label var marstat1 "Widowed, divorced, or separated"
label var marstat2 "Single"
label var marstat3 "Married"
fre education
quietly tab education, gen(education)
label var education1 "Low education"
label var education2 "Medium education"
label var education3 "Tertiary education"
fre parttime
quietly tab parttime, gen(parttime)
label var parttime1 "Marginal part-time (< 20 hrs.)"
label var parttime2 "Substantial part-time (20-34 hrs.)"
label var parttime3 "Full-time (35-80 hrs.)"
fre occgroups
quietly tab occgroups, gen(occgroups)
label var occgroups1 "Unskilled job"
label var occgroups2 "Skilled manual job"
label var occgroups3 "Skilled routine services job"
label var occgroups4 "High-skilled services"
fre industry
quietly tab industry , gen(industry)
label var industry1 "Agriculture"
label var industry2 "Industry and construction"
label var industry3 "Market services"
label var industry4 "Non-market services"
// Re-label some more variables here.
// Variable labels HAVE to be identical to those specified below.
// Formatting is possible here.
label var female "{bf:Female sex}"
label var smallfirm "{bf:Small firm} (< 10 employees)"
label var fixedterm "{bf:Fixed-term contract}"
label var jobtenure "{bf:Job tenure} (in years)"
label var supervisor "{bf:Supervisor status}"
// Estimate regression model
ologit posstend female age1-age3 age5-age10 marstat1 marstat3 ///
education1 education3 parttime1 parttime2 smallfirm fixedterm ///
jobtenure supervisor occgroups1 occgroups3 occgroups4 ///
industry1 industry3 industry4, cluster(cntry)
// Save regression parameters in data set
parmest, norestore eform label
// Add gaps to add some structure to the regression plots
ingap 2 11 13 15 21 24, rowlabel(label) ///
growlabel("Age ({it:Ref.} 30-34 years)" ///
"Marital status ({it:Ref.} Single)" ///
"Education ({it:Ref.} Medium)" ///
"Working hours ({it:Ref.} Full-time (35-80 hrs)" ///
"Occup. group ({it:Ref.} Skilled manual job)" ///
"Industry ({it:Ref.} Industry and construction)")
// Define label by hand to be able to determine order of predictors on axis
// Labels must be exactly the same as above
//
// Formatting axis label text seems
// to be working here as well
//
// An easier solution might be the one here:
// http://www.survey-design.com.au/Stata%20Graphs.html
// ("Odds ratio graph - selecting order of bars")
#delimit ;
label define label1 1 "{bf:Female sex}"
2 "{bf:Age} ({it:Ref.} 30-34 years)"
3 "15-19 years"
4 "20-24 years"
5 "25-29 years"
6 "35-39 years"
7 "40-44 years"
8 "45-49 years"
9 "50-54 years"
10 "55-59 years"
11 "60-64 years"
12 "{bf:Marital status} ({it:Ref.} Single)"
13 "Widowed, divorced, or separated"
14 "Married"
15 "{bf:Education} ({it:Ref.} Medium)"
16 "Low education"
17 "Tertiary education"
18 "{bf:Working hours} ({it:Ref.} Full-time (35-80 hrs)"
19 "Marginal part-time (< 20 hrs.)"
20 "Substantial part-time (20-34 hrs.)"
21 "{bf:Small firm} (< 10 employees)"
22 "{bf:Fixed-term contract}"
23 "{bf:Job tenure} (in years)"
24 "{bf:Supervisor status}"
25 "{bf:Occupational group} ({it:Ref.} Skilled manual job)"
26 "Unskilled job"
27 "Skilled routine services job"
28 "High-skilled services"
29 "{bf:Industry} ({it:Ref.} Industry and construction)"
30 "Agriculture"
31 "Market services"
32 "Non-market services"
33 "Constant"
34 "Constant" ;
#delimit cr
encode label, gen(label1) label(label1)
// Specifying a label in the -encode- command makes sure that -encode-
// does not sort labels in alphabetical order
eclplot estimate min95 max95 label1 ///
if label1 <= 32 /// Don't plot the cut values
, horizontal ylabel(1(1)32, labsize(vsmall)) /// Reduce font size on axis
xline(1) /// Add vertical line
xtitle("Odds ratio") ///
ytitle("Predictors") ///
title("Possibility to vary start and/or end of working day", span) ///
caption("Source: EU-LFS AHM 2010, authors' calculations." /*
*/ "Ordered logit regression, /*
*/ 95% CI's adjusted for clustering in countries", span)
Subscribe to:
Posts (Atom)

