Apr 24, 2020

Random graphs (145): Uncluttered line graphs

// Open General Social Survey data
use wtssall year health1 parsol ///
    if inlist(year, 2002, 2004, 2006, 2010, 2014, 2018) ///
    using "data/GSS7218_R2.DTA", clear

// Listwise deletion
keep if !missing(health1, parsol)

// Fix health variable
recode health1 (4 5   = 1 "Poor health") ///
               (3 2 1 = 0 "Good health"), gen(poorhealth)
label var poorhealth "Poor health"

// Collapse data set
collapse poorhealth [pw = wtssall], by(year parsol)
replace poorhealth = poorhealth * 100

// Create figure
foreach x of numlist 2002 2006 2010 2014 2018 {
 local 2002 gs11
 local 2006 gs11
 local 2010 gs11
 local 2014 gs11
 local 2018 gs11
 local `x'  red
 twoway (line poorhealth parsol if year == 2002, lcolor(`2002') lstyle(solid)) ///
        (line poorhealth parsol if year == 2006, lcolor(`2006') lstyle(solid)) ///
        (line poorhealth parsol if year == 2010, lcolor(`2010') lstyle(solid)) ///
        (line poorhealth parsol if year == 2014, lcolor(`2014') lstyle(solid)) ///
        (line poorhealth parsol if year == 2018, lcolor(`2018') lstyle(solid)) ///
       , title({bf:`x'}, justification(left) bexpand span) ///
         ytitle("% poor health") ///
         xtitle("Living standard compared to parents'") ///
         xlabel(1 `""Much" "better""' ///
                2 `""Somewhat" "better""' ///
                3 `""About" "the same""' ///
                4 `""Somewhat" "worse""' ///
                5 `""Much" "worse""' ///
                , val) ///
         name(year`x', replace) legend(off) nodraw
}

graph combine year2002 ///
              year2006 year2010 ///
              year2014 year2018, ///
      col(2) ysize(8) altshrink ///
      note("{it: Note:} Weighted with WTSSALL", size(vsmall)) ///
      name(figure, replace)