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))
Showing posts with label centile. Show all posts
Showing posts with label centile. Show all posts
May 29, 2016
Random graphs (88): Model predictions
Labels:
centile,
European Social Survey,
marginsplot,
Random graphs,
scores
May 26, 2016
Random graphs (86): Interaction plots
version 14
use ESS1e06_4.dta, clear
// Age variable
replace agea = . if agea == 999
qui centile(agea), centile(99.9)
replace agea = r(c_1) if age > r(c_1) & !missing(agea)
rename agea age
// Happiness variable
recode happy (77 88 99 = .)
// Education variable
recode eduyrs (77 88 99 = .)
qui centile eduyrs, centile(99.9)
replace eduyrs = r(c_1) if eduyrs > r(c_1) & !missing(eduyrs)
// Fit model
regress happy c.eduyrs##c.age##c.age, robust
// Caculate education slope as function of age
qui margins, dydx(eduyrs) over(age)
marginsplot, recastci(rarea) recast(line) ciopts(color(gs12)) ///
ytitle("Effect of education on happiness") ylabel(, format(%6.2f)) ///
xtitle("Age") xlabel(20(10)90) xmtick(14(1)93) ///
title("") name(slope, replace) xsize(4) nodraw
// Predict happiness for different values of age and education
qui margins, at(eduyrs=(9 12 15) age=(14 20 (5) 90 93))
marginsplot, xdimension(age) recastci(rarea) recast(connected) ciopts(color(gs12)) ///
ytitle("Predicted happiness") ylabel(, format(%6.1f)) ///
xtitle("Age") xlabel(20(10)90) xmtick(14(1)93) ///
legend(order(6 "15 yrs" 5 "12 yrs." 4 "9 yrs.") ///
title(Education, size(*.8)) pos(11) ring(0)) ///
title("") name(prediction, replace) xsize(4) nodraw
// Plot
graph combine slope prediction, xsize(8) row(1) note("{it:Source:} European Social Survey, round 1 (2002/2003).")
May 19, 2016
Random graphs (83): Quadratic by continuous interaction
unzipfile ZA4582_v1-0-0.dta.zip
use ZA4582_v1-0-0.dta, clear
// Fix variables
// Life satisfaction
recode v545 ( 0 = 0 "Completely dissatisfied") ///
(10 = 10 "Completely satisfied") ///
(96 = .a "Not asked") ///
(99 = .b "No response") ///
, gen(lsat)
label var lsat "Life satisfaction"
// Household income (OECD)
recode v924 (99996 = .d "Can't be determined") ///
(99997 = .a "Refused") ///
( 0 = 0 "No income") ///
(99998 = .b "Don't know") ///
(99999 = .c "No response") ///
, gen(income)
label var income "Income"
// Age, truncated at 99.9th percentile
recode v729 (997 = .a "Refused") ///
(999 = .b "No Response"), gen(age)
label var age "Age"
qui centile(age), centile(99.9)
replace age = r(c_1) if age > r(c_1) & !missing(age)
// Fit model
regress lsat c.age##c.age##c.income
// Calculate income percentiles
centile(income), centile(10 25 50 75 90)
local r10 = r(c_1)
local r25 = r(c_2)
local r50 = r(c_3)
local r75 = r(c_4)
local r90 = r(c_5)
// Calculate margins
margins, at(age=(20 (5) 90) income=(`r10' `r50' `r75' `r90'))
// Plot
marginsplot, recastci(rarea) ciopts(color(gs12)) ///
ytitle("Predicted life satisfaction") ///
legend(order(8 "90th percentile" ///
7 "75th percentile" ///
6 "50th percentile" ///
5 "10th percentile") ring(0) pos(11) ///
title("Equivalized household income", size(*.7))) ///
xtitle("Age") ylab(, format(%6.1f)) title("") ///
note(" " "{it:Source:} German General Social Survey (Allbus), doi: 10.4232/1.12439" ///
"{it:Note:} Gray-shaded areas denote 95% confidence intervals.", span)
erase ZA4582_v1-0-0.dta
Labels:
Allbus,
centile,
erase,
Interaction plot,
marginsplot,
Random graphs
May 11, 2016
Random graphs (82): Quadratic by categorical interaction
unzipfile output7138637360988071942.zip
use agea gndr happy using ESS1-6e01_1_F1, clear
// Generate age variable, truncated at 99.9th percentile
qui centile(agea), centile(99.9)
generate age = agea
replace age = r(c_1) if age > r(c_1) & !missing(age)
// Generate gender variable
generate female =(gndr == 2) if !missing(gndr)
// Fit model and plot
regress happy c.age##c.age##i.female
qui margins, at(age=(15(5)90) female=(0 1))
marginsplot, recastci(rarea) ciopts(color(gs12)) ytitle("Predicted happiness") ///
legend(order(3 "Men" 4 "Women") ring(0) pos(2)) xtitle("Age") ///
ylab(, format(%6.1f)) title("") ///
note(" " "{it:Source:} European Social Survey, round 1{c 150}6." ///
"{it:Note:} Gray-shaded areas denote 95% confidence intervals.", span)
Subscribe to:
Posts (Atom)



