Showing posts with label graph bar. Show all posts
Showing posts with label graph bar. Show all posts

Sep 18, 2019

Random graphs (142): Boxplot using twoway commands with overlaid data

use v358 v392 v585 v829 if inrange(v829, 1, 5) using "data allbus\ZA4612_v1-0-1.dta", clear

// Subjective social mobility
recode v829 (5 = 1 "Much lower status") ///
            (4 = 2 "Lower status") ///
            (3 = 3 "About equal") ///
            (2 = 4 "Higher status") ///
            (1 = 5 "Much higher status") ///
            (95 96 98 99 = .), gen(ssm)
label var ssm "Status of own job compared to father's"

// Respondent's social status ISEI
clonevar isei = v358
replace  isei =    . if inlist(isei, 0, 99)
replace  isei = v392 if missing(isei)
replace  isei =    . if inlist(isei, 0, 99)
label var isei "Respondent's ISEI"

// Father's social status ISEI
clonevar fisei = v585 
replace  fisei =    . if inlist(fisei, 0, 99)
label var fisei "Father's ISEI"

// Objective status mobility
gen osm = isei - fisei
label var osm "Objective status mobility"


// Boxplot using -graph- command graph box osm, over(ssm, descending) horizontal /// yline(0) l1title("Status of own job compared to father's" "(self-assessment)") /// name(figure1, replace)


// Boxplot using -twoway- command

// Calculate stuff for boxplot
qui bys ssm: sum osm, detail
qui bys ssm: egen min = pctile(osm), p(25) // Interquartile range
qui bys ssm: egen max = pctile(osm), p(75) // Interquartile range
qui bys ssm: egen med = median(osm)

// Plot
twoway (scatter ssm osm, msymb(o) jitter(2) mcolor(red%10)) ///
       (scatter ssm med, msymb(oh) mcolor(black)) ///
       (rspike  min max ssm, horizontal lcolor(black)), ///
        ylabel(1/5, valuelabel) xline(0) ///
        ytitle("Status of own job compared to father's" "(self-assessment)") ///
        legend(order(2 "Median" 3 "Interquartile range") ring(0) pos(11)) ///
        xtitle(Objective social mobility) name(figure2, replace)
drop min max med // Drop stuff for boxplot

Mar 28, 2018

Random graphs (130): Bar graph

clear
input str30 journal swb psw
"{it:ASR}" 31 3
"{it:AJS}" 13 1
"{it:ESR}" 55 1
`"{it:"Demography"}"' 62 7
`"{it:"Population Studies"}"' 35 3
`"{it:"Demographic Research"}"' 42 2
"{it:JMF}" 154 39
end

graph hbar swb psw, over(journal, sort(1)) ///
      legend(order(1 "Subjective wellbeing" 2 "Psychosocial wellbeing") ring(0) pos(2)) ///
      ytitle("Number of articles on Google Scholar using the term") name(swbvspsw, replace) ///
      note(" " "{it:Source:} Google Scholar, March 28, 2018", span)

May 24, 2017

Random graphs (95): Categorical variables

use "ZA4582_v1-0-0.dta", clear

recode v151 (9 = .a "No response") ///
            (8 = .b "Don't know") ///
            (7 = .c "Refused") ///
            (6 = .d "None of the strata") ///
            (5 =  1 "Upper class") ///
            (4 =  2 "Upper middle class") ///
            (3 =  3 "Middle class") ///
            (2 =  4 "Working class") ///
            (1 =  5 "Lower class") ///
           , gen(subjclass)
label var subjclass "Subjective social class"

generate nolabelyear = year     
label define ost_west 1 "Western Germany" 2 "Eastern Germany", modify
graph bar (count), over(subjclass, descending) /// over(nolabelyear, label(angle(vertical))) /// by(ost_west, note("{it:Source:} German General Social Survey (Allbus), doi: 10.4232/1.12439.", span) col(1)) /// percent stack asyvars ytitle(%) ysize(8) /// legend(rows(3) colfirst) name(figure1, replace)
tabplot subjclass nolabelyear, by(ost_west, /// note("{it:Source:} German General Social Survey (Allbus), doi: 10.4232/1.12439.", span)) /// percent(ost_west nolabelyear) /// showval(mlabsize(tiny)) xtitle("") /// xlabel(, angle(vertical)) name(figure2, replace)

Feb 11, 2017

Random graphs (93): Bold letters to label panels of a figure

// Read in data for Panel A
clear
input str30 time str30 sex swlb
"Marginal part-time" "Men" 7.0600364
"Marginal part-time" "Women" 7.25796249
"Substantial part-time" "Men" 6.870697962
"Substantial part-time" "Women" 6.885557977
"Full-time" "Men" 6.46086536 
"Full-time" "Women" 6.20409318
end

// Create Panel A
graph bar swlb, over(sex) over(time, sort(1)) ///
      ytitle("Predicted Satisfaction with" "the Work-Life Balance") ///
      xsize(6)  exclude0 ///
      yscale(range(6 7.4)) ylabel(6 (.2) 7.4, format(%6.1f)) ///
      title("{bf:A}", justification(left) bexpand span) ///
      name(A, replace) 

// Read in data for Panel B
clear
input str30 time str30 giis swlb
"Substantial part-time" "High gender equality" 7.172238806
"Substantial part-time" "Low gender equality" 6.292988109 
"Marginal part-time" "High gender equality" 7.357329866
"Marginal part-time" "Low gender equality"  6.843323499
"Full-time" "High gender equality" 6.435347496
"Full-time" "Low gender equality" 6.143352232
end

// Recode one variable so that categories are in right order
generate gii = 0 if giis == "Low gender equality"
replace  gii = 1 if giis == "High gender equality"
label define gii 0 `""Low" "gender" "equality""' ///
                 1 `""High" "gender" "equality""'
label val gii gii
drop giis

// Create Panel B
twoway (line swlb gii if time == "Marginal part-time") ///
       (line swlb gii if time == "Substantial part-time") ///
       (line swlb gii if time == "Full-time") ///
      , legend(order(1 "Marginal part-time" 2 "Substantial part-time" 3 "Full-time") pos(2)) ///
        ytitle("Predicted Satisfaction with" "the Work-Life Balance") ///
        xlabel(0 1, val) xtitle("") ///
        ylabel(6 (.2) 7.4, format(%6.1f)) ///
        name(B, replace) ///   
        title("{bf:B}", justification(left) bexpand span)

// Combine Panel A and Panel B
graph combine A B, row(2) ysize(8) xsize(6) ycommon

Mar 29, 2016

Random graphs (68): Bar graph

use sharew1_rel2-6-0_ch.dta, clear

recode ch001_ (0/4  =  0   "Less than five children") ///
              (5/17 =  100 "Five children and more") ///
              (-1   = .a "Refusal") ///
              (-2   = .b "Don't know") ///
             , gen(largefamilies)
   
graph bar largefamilies if country != 25, over(country, sort(largefamilies)) ///
          horizontal ytitle("% with five and more children") ///
   note(" " "{it:Source:} SHARE wave 1, doi:10.6103/SHARE.w1.260", span) ///
          yalternate

Aug 20, 2015

Random graphs (52): Stacked bar graph


// Source:
// Kupka, Markus S., Anna Pia Ferraretti, Jacques De Mouzon, Karin Erb, Thomas
//     D'Hooghe, José Antonio Castilla, Carlos Calhaz-Jorge, Christian De
//     Geyter, Veerle Goossens, and the European IVF Monitoring Consortium for
//     the European Society of Human Reproduction and Embryology. 2014.
//     "Assisted Reproductive Technology in Europe, 2010. Results Generated from
//     European Registers by ESHRE." Human Reproduction 29(10):2099-2113. doi:
//     10.1093/humrep/deu175

clear
input str20 cntry ivf icsi fer pgd ed ivm for
"Belgium"  15.9 46.0 30.9 2.2 5.0 0.0 0.0 100.0
"Denmark"  41.6 35.1 21.1 0.8 1.4 0.0 0.0 100.0
"Germany"  15.3 56.2 28.6 0.0 0.0 0.0 0.0 100.0
"United Kingdom" 37.0 40.1 18.1 1.2 3.3 0.1 0.1 100.0
"Italy"   14.9 74.5 6.4 0.0 0.0 0.0 4.1 100.0
"Spain"   5.9 49.5 14.9 4.7 22.0 0.0 3.1 100.0
"Slovenia"  27.9 53.7 17.2 0.8 0.4 0.0 0.0 100.0
"Czech Republic" 15.4 49.6 22.9 2.4 9.7 0.0 0.0 100.0
end



graph hbar ivf icsi fer pgd ed for, over(cntry, sort(ivf) desc) stack ///
      legend(label(1 "IVF") label(2 "ICSI") label(3 "FER") ///
      label(4 "PGD") label(5 "ED") label(6 "FOR") pos(12) row(1)) ///
      ytitle("Percentage of all ART treatments, 2010") name(figure2, replace) ///
   scheme(lean1)

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)

May 7, 2014

Random graphs (20): Bar graph

clear

// Table from Vaupel and Loichinger 2006, 
// "Redistributing Work in Aging Europe,"
// Science 312(5782):1911-1913.
// doi: 10.1126/science.1127487
// Table 1

input str2 country r2005 r2025 rchange h2005 h2025 hchange
DE  1.27  1.47  16  16.28  14.95  -8
DK  0.97  1.12  15  17.46  16.11  -8
FR  1.43  1.69  18  15.09  13.63  -10
IT  1.59  1.86  17  15.19  13.48  -11
NL  1.01  1.20  19  15.31  13.88  -9
UK  1.09  1.19  9  17.32  16.34  -6
US  1.09  0.99  -9  18.71  18.29  -2
end

drop rchange hchange // drop unnecessary columns

graph bar r2005 r2025, over(country) bargap(-30) ///
      ytitle("Ratio nonworkers per worker") ///
      legend(label(1 "2005") label(2 "2025") row(1)) ///
      ylabel(,format(%6.1f)) ///  Format axis labels
      name(r, replace)

graph bar h2005 h2025, over(country) bargap(-30) ///
      ytitle("Hours worked per week per capita") ///
      legend(label(1 "2005") label(2 "2025")) ///
      ylabel(,format(%6.1f)) ///
      name(h, replace)
   
grc1leg r h, xcommon row(1) ///
             note("{it: Source:} Vaupel and Loichinger 2006, p. 1912" ///
                  "{it: Note:} The values for 2025 assume change in the" ///
                  "population pyramid but no change in labor force " ///
                  "participation or effort" "by age and sex.", span)