Nov 16, 2012

Random Graphs (5): Combining plots of means


set autotabgraphs on  // Recycle graph window

import excel "X:\Data\Desktop\means.xlsx", sheet("Sheet1") ///
             firstrow clear case(lower)
  // Read in aggregate data from Excel sheet:
  // - Variable name (variable) [string]
  // - Country name (country) [string]
  // - Average score (mean)
  // - Confidence bounds (lerr uerr)

// Create numerical country variable for x-axis:
// Fast alternative: Use -encode- if you do not
// want to manipulate the order of countries

generate cntry = 1 if country == "SE"
replace  cntry = 2 if country == "UK"
replace  cntry = 3 if country == "NL"
replace  cntry = 4 if country == "DE"
replace  cntry = 5 if country == "PT"

label define cntry 1 "SE" 2 "UK" 3 "NL" 4 "DE" 5 "PT"
label val cntry cntry
label var cntry "Country"

graph drop _all  // Drop graphs in memory, usefulfor re-running this file

twoway (scatter mean cntry if variable == "Job autonomy") ///
       (rcap lerr uerr cntry if variable == "Job autonomy") ///
       , legend(off) xlabel(, valuelabels) ///
         ytitle("Job autonomy") xscale(off) name(JA)

twoway (scatter mean cntry if variable == "WF culture") ///
       (rcap lerr uerr cntry if variable == "WF culture") ///
       , legend(off) xlabel(, valuelabels) ///
         ytitle("WF culture") xscale(off) name(WFC)

twoway (scatter mean cntry if variable == "WF supervisor support") ///
       (rcap lerr uerr cntry if variable == "WF supervisor support") ///
       , legend(off) xlabel(, valuelabels) ///
         ytitle("WF supervisor support") xscale(off) name(WFSS)

twoway (scatter mean cntry if variable == "WF co-worker support") ///
       (rcap lerr uerr cntry if variable == "WF co-worker support") ///
       , legend(off) xlabel(, valuelabels) ///
         ytitle("WF co-worker support") xscale(off) name(WFCS)

twoway (scatter mean cntry if variable == "FWA use") ///
       (rcap lerr uerr cntry if variable == "FWA use") ///
       , legend(off) xlabel(, valuelabels) ///
         ytitle("FWA use") name(FWA)

graph combine JA WFC WFSS WFCS FWA, col(1) xcommon imargin(b = 0 t = 0) ysize(10)