Jan 8, 2015

Random graphs (42): Stacked bar graph

 
use "ESS3e03_5.dta", clear

// Drop two remote countries

drop if cntry == "UA"
drop if cntry == "RU"

// Prepare variables of interest

  // Country variable
encode(cntry), gen(country)
label define country 12 "UK", modify

  // Keep only respondents asked about women (split ballot)
keep if icsbfm == 1

  /// Question about values
recode aftjbyc (1 2 = 1  "(Strongly) disapprove") ///
               (3   = 2  "Neutral") ///
               (4 5 = 3  "(Strongly) approve") ///
               (7/9 = .a "Missing/NA") ///
              , gen(value) label(value)
quietly tab value, gen(val)
ren val1 disapprove
ren val2 neutral
ren val3 approve

   // Sex
generate female = (gndr == 2) if gndr != .a
drop if female == .

// Calculate average scores across all countries by gender
preserve
collapse (mean) disapprove neutral approve [pweight = dweight], by(female)
gen country = 50  // Assign some value to sample average
tempfile euaverage
save `euaverage', replace
restore

// Calculate average scores for each country by gender
collapse (mean) disapprove neutral approve [pweight = dweight], by(country female)

// Add average score
append using `euaverage'
label define country 50 "{bf:EU}", modify    // Add bold label for sample averages

// Plot
graph bar approve neutral disapprove if female == 1 ///
        , over(country, sort(approve) descending label(alternate)) stack percentages ///
          title("Popular (dis)approval of a full-time" "working woman with a child under 3 years of age") ///
          ytitle("% of women") yscale(range(0 100)) ylabel(0(20)100) legend(off) ///
          name(women, replace)

graph bar approve neutral disapprove if female == 0 ///
        , over(country, sort(approve) descending label(alternate)) stack percentages ///
          ytitle("% of men") yscale(range(0 100)) ylabel(0(20)100) ///
          legend(label(3 "(Strongly) disapprove") ///
                 label(2 "Neutral") ///
                 label(1 "(Strongly) approve") ///
                 order(1 2 3) pos(6) row(1)) ///
          caption(" " ///
                  "{it: Source:} European Social Survey 2006/07, own calculations." ///
                  `"{it: Note:} "EU" refers to average for the 20 EU member states in this Figure."', ///
                  span size(small)) ///
          name(men, replace)
  
graph combine women men, col(1) ysize(8)