Mar 15, 2013

Random graphs (7): Differences in percentages across groups

*findit labutil // For the -labmask- command
*ssc install kountry

clear 
version 12 
  
// Download date from Eurostat, lfsa_eppga 
// Part-time employment as percentage of the total employment 
// From 15 to 64 years

input str60 geo m2011 f2011
EU27 8.1 31.6
Belgium 9.2 43.3
Bulgaria 2.0 2.4
"Czech Republic" 1.8 8.5
Denmark 14.2 37.0
Germany 9.0 45.1
Estonia 5.0 13.5
Ireland 12.5 35.2
Greece 4.2 10.0
Spain 5.9 23.4
France 6.5 29.9
Italy 5.5 29.3
Cyprus 6.1 12.1
Latvia 7.0 10.4
Lithuania 6.6 9.9
Luxembourg 4.3 35.9
Hungary 4.4 8.8
Malta 5.3 25.6
Netherlands 24.3 76.5
Austria 7.8 43.4
Poland 4.7 10.4
Portugal 7.0 13.7
Romania 8.7 10.1
Slovenia 7.1 12.2
Slovakia 2.6 5.6
Finland 9.4 19.0
Sweden 12.3 39.3
"United Kingdom" 11.0 42.2
Iceland 9.9 31.7
Norway 13.7 42.1
Switzerland 12.4 59.4
end 
 
// Country 
kountry geo, from(other) stuck
ren _ISO3N_ ctry
kountry ctry, from(iso3n) to(iso2c)
kountryadd "Former Yugoslav Republic of Macedonia, the" to "Macedonia" add
replace _ISO2C_ = "EU-27" if geo == "EU27" 
drop ctry
ren _ISO2C_ cntry 
  // Create non-string version of country variable
encode cntry, gen(country)
 
// Drop unnecessary cases
drop if cntry == "MK"
drop if cntry == "HR" 
drop if cntry == "TR" 

// First attempts:
graph bar f2011 m2011, over(cntry, sort(1) desc label(angle(90))) ///
      legend(label(2 "Men") label(1 "Women")) ///
   xsize(8.25) ysize(4)
// A bar graph is too cluttered

graph dot f2011 m2011, over(cntry, sort(1) desc) ///
      legend(label(2 "Men") label(1 "Women")) ///
   xsize(8.25) ysize(4)
// Can I have that vertically as well?

twoway dot m2011 f2011 country, vertical ///
      legend(label(1 "Men") label(2 "Women") ring(0) pos(1)) ///
   xlabel(1/31, valuelabels ang(v)) ///    // turn on labels
   xtitle("") ///
   ytitle("% part-time of total employment in 2011") ///
   caption("Source: Eurostat, lfsa_eppga, 2013-03-15", span) ///
   xsize(8.25) ysize(4)
// Can I sort countries by size of the gender gap?

// Set up sort order
gen diff = f2011 - m2011  // Gender gap
egen order = rank(-diff), unique  // Create rank variable
labmask order, value(country) decode // Assign value
  // labels of country to variable order based on its values
   
// Create graph
twoway dot m2011 f2011 order, vertical ///
      legend(label(1 "Men") label(2 "Women") ring(0) pos(1)) ///
   xlabel(1/31, valuelabels ang(v)) ///    // turn on labels
   xtitle("") ///
   ytitle("% part-time of total employment in 2011") ///
   caption("Source: Eurostat, lfsa_eppga, 2013-03-15", span) ///
   xsize(8.25) ysize(4)