Showing posts with label input. Show all posts
Showing posts with label input. Show all posts

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

Feb 11, 2016

Random graphs (57): Odds ratio plots


clear

// ART mothers
input str20 var or lb ub
agele30    . . .
age3039 4.25 3.872 4.668
agege40 14.23 12.746 15.893
foreign . . .
italian 1.69 1.534 1.865
unmarried . . .
married 2.41 2.239 2.597
marriedother 1.78 1.515 2.083
notemployed . . .
employed 1.22 1.132 1.318
loed . . .
mied 1.15 1.069 1.242
hied 1.17 1.077 1.266
prevlivebirth . . .
noprevlivebirth 7.63 7.055 8.248
nomiscarriage . . .
miscarriage 1.14 1.06 1.217
end

encode var, gen(var1)

recode var1 ( 3 =  1 "{bf:Age} ({it:Ref.} <= 30 y)") ///
            ( 1 =  2 "30{c 0150}39 y") ///
   ( 2 =  3 "40+ y") ///
   ( 5 =  4 "{bf:Citizenship} ({it:Ref.} foreign)") ///
   ( 7 =  5 "Italian") ///
   (17 =  6 "{bf:Marital status} ({it:Ref.} unmarried)") ///
   ( 9 =  7 "Married") ///
   (10 =  8 "Other marital status") ///
   (15 =  9 "{bf:Occ. status} ({it:Ref.} not employed)") ///
   ( 4 = 10 "Employed") ///
   ( 8 = 11 "{bf:Education} ({it:Ref.} low)") ///
   (11 = 12 "Medium") ///
   ( 6 = 13 "High") ///
   (16 = 14 "{bf:Previous live birth} ({it:Ref.} yes)") ///
   (14 = 15 "No") ///
   (13 = 16 "{bf:Previous miscarriage} ({it:Ref.} no)") ///
   (12 = 17 "Yes") ///
   , gen(var2)

eclplot or lb ub var2, horiz ///
                  ylabel(1(1)17, val) ///
                  xline(1) xlabel(1 (1) 10 15) xtitle("Odds ratio") xscale(log) ///
                  ytitle("Predictors") name(art_users, replace) //ysize(6) xsize(5.5)
clear

input str20 var or lb ub
noart . . . 
others 0.853 0.566 1.285
icsi 1.071 0.906 1.267
ivf 1.3 1.109 1.524
iui 0.977 0.723 1.318
ph 1.256 0.857 1.84
nomiscarriage  . . .  
miscarriage  1.591 1.542 1.641
previouslivebirth . . .
nopreviouslivebirth 1.031 1.003 1.061
loed . . .
mied 1.257 1.219 1.297
hied 1.997 1.916 2.081
notemployed . . .  
employed 1.066 1.032 1.102
unmarried  . . .
married 1.218 1.182 1.255
foreign . . .
italian 0.949 0.917 0.983
agege40  . . .
age3039 2.888 2.777 3.003
agele30 4.183 3.993 4.383
end 

encode var, gen(var1)

recode var1 ( 2 =  1 "{bf:Age} ({it:Ref.} 40+ y)") ///
            ( 1 =  2 "30{c 0150}39 y") ///
   ( 3 =  3 "<= 30 y") ///
   ( 5 =  4 "{bf:Citizenship} ({it:Ref.} foreign)") ///
   ( 8 =  5 "Italian") ///
   (22 =  6 "{bf:Marital status} ({it:Ref.} unmarried)") ///
   (12 =  7 "Married") ///
       (18 =  8 "{bf:Occ. status} ({it:Ref.} not employed)") ///
   ( 4 =  9 "Employed") ///
   (11 = 10 "{bf:Education} ({it:Ref.} low)") ///
   (13 = 11 "Medium") ///
   ( 6 = 12 "High") ///
   (21 = 13 "{bf:Previous live birth} ({it:Ref.} yes)") ///
   (17 = 14 "No") ///
   (16 = 15 "{bf:Previous miscarriage} ({it:Ref.} no)") ///
   (14 = 16 "Yes") ///
   (15 = 17 "{bf:Conception method} ({it:Ref.} natural)") ///
   (20 = 18 "Pharmacological") ///
   ( 9 = 19 "IUI") ///
   (10 = 20 "IVF") ///
   ( 7 = 21 "ICSI") ///
   (19 = 22 "Others") ///
      , gen(var2)


eclplot or lb ub var2, horiz ///
                  ylabel(1(1)22, val) ///
                  xline(1) xlabel(0.6 (1) 5) xtitle("Odds ratio") xscale(log) ///
                  ytitle("Predictors") name(livebirth, replace)

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)

Dec 18, 2014

Random graphs (40): Line plot

clear 
// Read in Table
input str4 cntry P1970 P1991 P1998 P2008 S1970 S1991 S1998 S2008 T1970 T1991 T1998 T2008
EU15 16.2 7.6 4.5 3.4 37.4 28.6 26.6 23.2 54 73 68.9 73.5
DE 8 3.4 2.5 2.1 48 35 30.4 25.3 44 62 67.1 72.5
FI 20 8 6.3 4.8 34 29 27.8 25.6 46 63 65.9 69.6
NL 6 4 3.6 3 36 24 19.9 16.7 58 72 76.5 80.3
SE 8 4 3.1 2.2 39 28 25.1 22.7 53 68 71.8 75.1
UK 3 2.1 1.9 1.5 42 25 . 17.7 55 73 75.3 80.7
CZ 13.5 10 5.6 3.5 49.4 45.9 41.4 38 37 44 53 58.6
end

// Crazy stuff to bring it into shape
preserve

drop S1970-T2008

reshape long P, i(cntry) j(year)

tempfile p
save `p', replace

restore

preserve 
drop P1970-P2008 T1970-T2008

reshape long S, i(cntry) j(year)

tempfile s
save `s', replace

restore

drop P1970-S2008

reshape long T, i(cntry) j(year)

merge 1:1 cntry year using `p'
drop _merge
merge 1:1 cntry year using `s'

// Plot
twoway (scatter P year if cntry == "EU15", connect(L)) ///
       (scatter S year if cntry == "EU15", connect(L)) ///
       (scatter T year if cntry == "EU15", connect(L)) ///
      , ytitle("Percentage of EU-15 workforce") ///
        xtitle("") ///
        note(" " "{it: Source:} Mau and Verwiebe 2010, pp. 153{c 150}4", span) /// 
        legend(label(1 "{bf:Primary sector:}" "Agriculture") ///
               label(2 "{bf:Secondary sector:}" "Industry and" "construction") /// 
               label(3 "{bf:Tertiary sector:}" "Services")) ///
        xlabel(1970 1991 1998 2008)


Oct 18, 2013

Random graphs (17): Differences in percentages across groups

clear

// Read in data

/// Employment (main characteristics and rates) - annual averages [lfsi_emp_a]
/// Last update: 10-07-2013 
/// Employment rate (20 to 64 years) 

input str33 geo total male female
"European Union (28 countries)" 68.4 74.5 62.3
"European Union (27 countries)" 68.5 74.6 62.4
"Belgium" 67.2 72.7 61.7
"Bulgaria" 63.0 65.8 60.2
"Czech Republic" 71.5 80.2 62.5
"Denmark" 75.4 78.6 72.2
"Germany" 76.7 81.8 71.5
"Estonia" 72.1 75.2 69.3
"Ireland" 63.7 68.1 59.4
"Greece" 55.3 65.3 45.2
"Spain" 59.3 64.5 54.0
"France" 69.3 73.8 65.0
"Croatia" 55.4 60.6 50.2
"Italy" 61.0 71.6 50.5
"Cyprus" 70.2 76.1 64.8
"Latvia" 68.2 70.2 66.4
"Lithuania" 68.7 69.4 67.9
"Luxembourg" 71.4 78.5 64.1
"Hungary" 62.1 68.1 56.4
"Malta" 63.1 79.0 46.8
"Netherlands" 77.2 82.5 71.9
"Austria" 75.6 80.9 70.3
"Poland" 64.7 72.0 57.5
"Portugal" 66.5 69.9 63.1
"Romania" 63.8 71.4 56.3
"Slovenia" 68.3 71.8 64.6
"Slovakia" 65.1 72.8 57.3
"Finland" 74.0 75.5 72.5
"Sweden" 79.4 81.9 76.8
"United Kingdom" 74.2 80.0 68.4
"Iceland" 81.8 84.4 79.1
"Norway" 79.9 82.4 77.3
"Switzerland" 82.0 87.9 76.0
end

/// Create country variable
kountry geo, from(other) stuck
ren _ISO3N_ ctry
kountry ctry, from(iso3n) to(iso2c)
replace _ISO2C_ = "EU-27" if geo == "European Union (27 countries)"
replace _ISO2C_ = "EU-28" if geo == "European Union (28 countries)"
replace _ISO2C_ = "GB" if geo == "United Kingdom"
replace _ISO2C_ = "EL" if geo == "Greece"
drop ctry
ren _ISO2C_ cntry

drop if inlist(cntry, "EU-28", "IS", "CH", "NO")

graph dot male female, over(cntry, sort(total) ///
      label(angle(v))) vertical exclude0 ///
   legend(label(1 "Males") label(2 "Females") ring(0)) ///
   ytitle("Employment rate among 20-64 year-olds," "2012") ///
   yline(75) text(76 12 "Europe 2020 target") ///
   note( ///
          "{it:Source:} Eurostat, lfsi_emp_a, date of extraction: 2013-08-04" ///
          "{it:Note:} Countries sorted by total employment rates", span)

Mar 18, 2013

Random graphs (9): Bar graphs

clear

// Copy and paste data from here:
// http://epp.eurostat.ec.europa.eu/cache/
// ITY_PUBLIC/3-07032013-AP/EN/3-07032013-AP-EN.PDF

input str30 geo ///
      teachers_primary ///
   teachers_secondary ///
   teachers_tertiary ///
   physicians ///
   managers
EU27 85 59 40 45 33
Belgium 81 61 45 36 30
Bulgaria 94 78 48 . 37
"Czech Republic" 97 58 36 54 26
Denmark 69 . . 45 28
Germany 84 50 39 42 30
Estonia 93 73 . 74 36
Ireland 85 65 . 39 34
Greece . . . 39 23
Spain 75 50 40 51 30
France 83 54 36 41 40
Italy 96 63 36 37 25
Cyprus 83 59 39 . 15
Latvia 93 80 59 74 45
Lithuania 96 79 55 70 39
Luxembourg 74 50 43 30 25
Hungary 96 65 38 54 41
Malta 85 43 30 37 24
Netherlands 85 50 40 45 30
Austria 90 53 38 44 27
Poland 85 66 43 57 39
Portugal 80 68 44 51 34
Romania 86 67 46 69 31
Slovenia 97 66 39 59 38
Slovakia 89 71 44 56 31
Finland 79 58 50 55 32
Sweden 82 52 43 45 35
"United Kingdom" 87 60 43 45 35
Iceland 81 52 47 33 41
Liechtenstein 78 44 27 . .
Norway 74 50 43 43 32
Switzerland 81 40 37 36 33
end

// Label variables
label var geo "Country"
label var teachers_primary "Female teachers in primary education"
label var teachers_secondary "Female teachers in upper secondary education"
label var teachers_tertiary "Female academic staff in tertiary education"
label var physicians "Female physicians (2010)"
label var managers "Female managers"

// Country variable
kountry geo, from(other) stuck
ren _ISO3N_ ctry
kountry ctry, from(iso3n) to(iso2c)
replace _ISO2C_ = "EU-27" if geo == "EU27"
drop ctry
ren _ISO2C_ cntry

drop if cntry == "LI"

// Draw graph
graph hbar managers, over(cntry, sort(1) desc) ///
  xsize(5.5) ysize(8) ///
  caption("Source: Eurostat News Release 37/2013", span) ///
/*note("Includes both corporate managers ///
  and managers of small enterprises", span)*/ ///
  ytitle("Proportion of female managers in 2011")

// Black bar created via the graph editor