// Prepare ESS round 8
use cntry essround wrkctra dweight using "ESS8e01.dta", clear
recode wrkctra (6 = .a) (7 = .b) (8 = .c) (9 = .d)
// Add ESS rounds 1-7
append using "ESS1-7e01.dta", keep(cntry essround wrkctr wrkctra dweight)
// Prepare variables
generate nocontract = (wrkctra == 3) if !missing(wrkctra)
kountry cntry, from(iso2c)
rename NAMES_STD country
// Prepare files for post commands
tempname foo1
tempname foo2
postfile `foo1' str20 country essround ll nocontract ul using `foo2', replace
qui levelsof country, local(country)
// Loop
foreach x of local country {
foreach i of numlist 1/8 {
capture logit nocontract [pw = dweight] if country == "`x'" & essround == `i'
if _rc == 0 {
qui margins [pw = dweight]
matrix prevs = r(table)
local prev = prevs[1,1] * 100
local ll = prevs[5,1] * 100
local ul = prevs[6,1] * 100
*di "`x'" _skip(5) `i' _skip(5) `ll' _skip(5) `prev' _skip(5) `ul'
post `foo1' ("`x'") (`i') (`ll') (`prev') (`ul')
}
}
}
postclose `foo1'
// Plot estimates
use `foo2', clear
// Fix value label
label define essround 1 "2002" 2 "2004" 3 "2006" 4 "2008" ///
5 "2010" 6 "2012" 7 "2014" 8 "2016", modify
label val essround essround
// First plot
sort country essround
twoway (rarea ll ul essround, lcolor(white)) ///
(connected nocontract essround), ///
by(country, ///
note("") ///
legend(off)) ///
xlabel(1/8, val ang(90)) ///
xtitle("") ytitle("% without job contract") ///
name(figure2a, replace) ysize(9)
// Second plot
reshape wide ll ul nocontract, i(country) j(essround)
scores average = mean(nocontract*)
egen order_ = rank(average), unique
labmask order_, value(country)
twoway (dot nocontract1 order_, horizontal) ///
(dot nocontract2 order_, horizontal) ///
(dot nocontract3 order_, horizontal) ///
(dot nocontract4 order_, horizontal) ///
(dot nocontract5 order_, horizontal) ///
(dot nocontract6 order_, horizontal) ///
(dot nocontract7 order_, horizontal) ///
(dot nocontract8 order_, horizontal) ///
(rspike ul1 ll1 order_, horizontal) ///
(rspike ul2 ll2 order_, horizontal) ///
(rspike ul3 ll3 order_, horizontal) ///
(rspike ul4 ll4 order_, horizontal) ///
(rspike ul5 ll5 order_, horizontal) ///
(rspike ul6 ll6 order_, horizontal) ///
(rspike ul7 ll7 order_, horizontal) ///
(rspike ul8 ll8 order_, horizontal), ///
ylabel(1/32, val) ytitle("") xscale(alt) ///
xtitle("% without job contract") ///
legend(order(1 "2002" 2 "2004" 3 "2006" 4 "2008" ///
5 "2010" 6 "2012" 7 "2014" 8 "2016") ///
pos(5) ring(0)) ///
name(figure2b, replace) ysize(9)
graph combine figure2a figure2b, ///
col(2) name(figure2, replace) ///
note(" " "{it:Source:} European Social Survey 2002-16, weighted data. {it:Note:} Error bands/spikes denote 95% confidence intervals", span size(*.7))
Showing posts with label scores. Show all posts
Showing posts with label scores. Show all posts
Nov 17, 2017
Random graphs (119): Line plots and dot plots
Labels:
European Social Survey,
foreach,
graph combine,
kountry,
labmask,
logit,
margins,
postfile,
Random graphs,
reshape,
scores,
twoway dot,
twoway rarea,
twoway rspike,
weight
Nov 16, 2017
Random graphs (118): Dot plot
clear
input str5 cntry eqls2003 eqls2007 ewcs2005 ewcs2010 eusilc2014
SE 0.021949 0.030043 0.00213 0.000918 .
FI 0.022075 0.013452 0.02246 0.011247 0.00012
HR . 0.018228 0.017975 0.013302 .
SK 0.011168 0.035384 0.013425 0.019773 0.003893
CZ 0.005486 0.064484 0.008917 0.005968 0.000863
NO . 0.0226 0.021383 0.018745 0.012686
CH . . 0.028731 . .
HU 0.018815 0.060927 0.044574 0.013885 0.019517
SI 0.025373 0.030885 0.095199 0.019257 0.001327
NL 0.035021 0.048701 0.021501 0.034217 .
BE 0.039831 0.088688 0.025436 0.006923 0.01386
EE 0.027082 0.048187 0.052969 0.052337 0.006435
FR 0.030219 0.074314 0.040906 0.01435 .
LT 0.049985 0.077502 0.05434 0.032847 0.006778
BG 0.037858 0.063697 0.065784 0.032313 0.039127
PL 0.023636 0.075742 0.06099 0.037228 .
LU 0.106816 0.102864 0.004992 0.006159 0.032854
DE 0.090262 0.040957 0.038157 0.035452 .
RO 0.063563 0.072842 0.070762 0.022769 .
LV 0.09474 0.077167 0.054927 0.034465 0.038258
IT 0.040173 0.128064 0.06421 0.036467 .
AT 0.057465 0.132496 0.095462 0.05458 .
ES 0.112064 0.127856 0.086716 0.076224 0.038867
DK 0.129036 0.103272 0.107504 0.040896 .
UK 0.120762 0.124342 0.150114 0.083238 0.024998
ME . . . 0.101533 .
PT 0.173582 0.179532 0.073722 0.113514 0.091105
RS-KM . . . 0.160115 .
MK . 0.194579 . 0.128292 .
IE 0.270422 0.359196 0.293468 0.240577 0.03082
AL . . . 0.275311 .
GR 0.404795 0.53023 0.286437 0.292037 0.144072
MT 0.302118 0.465496 0.387637 0.277371 .
CY 0.322423 0.54425 0.436497 0.395157 .
TR 0.564689 0.496668 0.689807 0.643683 .
end
scores average = mean(eqls2003 eqls2007 ewcs2005 ewcs2010)
kountry cntry, from(iso2c) marker
rename NAMES_STD country
replace country = "Kosovo" if country == "rskm"
egen order_ = rank(average), unique
labmask order_, value(country)
twoway (dot eqls2003 order_, horizontal) ///
(dot eqls2007 order_, horizontal) ///
(dot ewcs2005 order_, horizontal) ///
(dot ewcs2010 order_, horizontal) ///
(dot eusilc2014 order_, horizontal) ///
, ylabel(1/35, val) ysize(9) ///
ytitle("") xscale(alt) ///
xtitle("Proportion without job contract") ///
legend(order(1 "EQLS 2003" ///
2 "EQLS 2003" ///
3 "EWCS 2005" ///
4 "EWCS 2010" ///
5 "EU-SILC 2014") title("Data source") pos(5) ring(0))
May 29, 2016
Random graphs (88): Model predictions
use gndr fcldbrn yrbrn health agea ///
fltdpr flteeff slprl wrhpp fltlnl enjlf fltsd cldgng cntry ///
using ESS3e03_5.dta, clear
// Gender variable
gen female = (gndr == 2) if gndr !=9
// Calculate age at first birth
recode fcldbrn (6666 = .a "NA") ///
(7777 = .b "Refusal") ///
(8888 = .c "Don't know") ///
(9999 = .d "No answer") ///
, gen(yrfirstbirth)
recode yrbrn (7777 = .b "Refusal") ///
(8888 = .c "Don't know") ///
(9999 = .d "No answer") ///
, gen(yrbirth)
generate afb = yrfirstbirth - yrbirth
qui centile afb, centile(.5 99) // Truncate
replace afb = r(c_1) if afb < r(c_1)
replace afb = r(c_2) if afb >= r(c_2) & !missing(afb)
// Self-rated health variable
recode health ( 1 = 4 "Very good") ///
( 2 = 3 "Good") ///
( 3 = 2 "Fair") ///
( 4 = 1 "Bad") ///
( 5 = 0 "Very bad") ///
( 7 = .a "Refusal") ///
( 8 = .b "Don't know") ///
( 9 = .c "No answer") ///
, generate(srh)
// Depression variable
recode fltdpr flteeff slprl wrhpp fltlnl ///
enjlf fltsd cldgng ///
(7 = .a) (8 = .b) (9 = .c)
recode wrhpp enjlf (1 = 4) (2 = 3) (3 = 2) (4 = 1) (. = .)
scores depression = mean(fltdpr flteeff slprl wrhpp fltlnl enjlf fltsd cldgng)
// Age variable
recode agea (999 = .a)
// Models and plots
regress srh i.afb i.agea if female == 1, cluster(cntry)
qui margins, over(afb)
marginsplot, ytitle("Predicted self-rated health") xtitle("Age at first birth") ///
name(womensrh, replace) recastci(rarea) ciopts(color(gs12)) xsize(3) ///
title("") ylabel(2 (.2) 3.2, format(%6.1f)) nodraw
regress depression i.afb i.agea if female == 1, cluster(cntry)
qui margins, over(afb)
marginsplot, ytitle("Predicted depression") xtitle("Age at first birth") ///
name(womendep, replace) recastci(rarea) ciopts(color(gs12)) xsize(3) ///
title("") ylabel(1.2 (.2) 2.4, format(%6.1f)) nodraw
regress srh i.afb i.agea if female == 0, cluster(cntry)
qui margins, over(afb)
marginsplot, ytitle("Predicted self-rated health") xtitle("Age at first birth") ///
name(mensrh, replace) recastci(rarea) ciopts(color(gs12)) xsize(3) ///
title("") ylabel(2 (.2) 3.2, format(%6.1f)) nodraw
regress depression i.afb i.agea if female == 0, cluster(cntry)
qui margins, over(afb)
marginsplot, ytitle("Predicted depression") xtitle("Age at first birth") ///
name(mendep, replace) recastci(rarea) ciopts(color(gs12)) xsize(3) ///
title("") ylabel(1.2 (.2) 2.4, format(%6.1f)) nodraw
graph combine womensrh womendep, col(1) ysize(8) name(a, replace) ///
title("Women", span) nodraw
graph combine mensrh mendep, col(1) ysize(8) name(b, replace) ///
title("Men", span) nodraw
graph combine a b, col(2) ysize(8) xsize(8) ycommon xcommon ///
note("{it:Source:} European Social Survey, round 3." ///
"{it:Note:} All models control for age as dummy variables. 95% CI's based on robust SE's", span size(*.9))
Labels:
centile,
European Social Survey,
marginsplot,
Random graphs,
scores
Sep 1, 2014
Random graphs (30): Log-log histograms
Healy and Moody (2014) recommend log-log histograms as an alternative to regular histograms. Given the fact that important variables in Sociology are often highly skewed, log-log histograms reveal greater details at the upper end of the distribution
// Membership variables of the first round (2002) of the ESS
use sptcmmb cltommb trummb prfommb ///
cnsommb hmnommb epaommb rlgommb ///
prtymmb setommb sclcmmb othvmmb using "ESS1e06.3_F1.dta", clear
// Generate count variable of memberships
scores memberships = total(sptcmmb cltommb trummb prfommb ///
cnsommb hmnommb epaommb rlgommb ///
prtymmb setommb sclcmmb othvmmb)
// Standard histogram
twoway (histogram memberships, percent discrete), ///
xtitle("Total no. of memberships in" "voluntary associations in last 12 mo.") ///
ytitle("Respondents in ESS round 1 (%)") xlabel(0/12) name(a, replace)
// Log-log histogram
twoway__histogram_gen memberships, gen(y x) width(1) fraction
replace y = y * 100 // Convert fractions to %
scatter y x, yscale(log) xscale(log) ///
xtitle("Total no. of memberships in" "voluntary associations in last 12 mo.") ///
ytitle("Respondents in ESS round 1 (%)") xlabel(0/12) ///
ylab(.1 1 10 20 40) ///
name(b, replace)
graph combine a b
Reference
Healy, Kieran, and James Moody. 2014. "Data Visualization in Sociology." Annual Review of Sociology 40:105-128. doi: 10.1146/annurev-soc-071312-145551
Subscribe to:
Posts (Atom)



