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)