/******************* session 3: Descriptive Stats Johanna Sophie Quis Bamberg Graduate School of Social Sciences (BAGSS) University of Bamberg Data: National Educational Panel Study (NEPS) - Additional Study Baden-Wurttemberg(BW A72 & A73, Version D_2-0-0) Procedure 1. Control Distribution of G8 / G9 Students 2. Age / Gender / Books at home composition 3. Satisfaction 4. Histograms 5. t-Tests 6. Summary Stats for all interesting variables 7. first regressions ********************/ // initialize working environment *run "init.do" *run "session1_Profile.do" // Prepare data *do "session2_mergeProfile.do" local sessionnum 3 *label language en *strimplify _all, verbose // open log file *log using "${logDir}/sessionsessionnum'.smcl", smcl replace name(smcl) *log using "${logDir}/sessionsessionnum'.log", text replace name(txt) * note: ID_t uniquely identifies a row! use "${dataDir}mentalhealthadjusted", clear set more off isid ID_t gen female_g8 = female * txg8 *************************************************** * 1) Control Distribution of G8 / G9 Students *************************************************** * What role do G8 old students play? * they seem to be above average in Abitur results * @fixlater does this matter?! format %3.1g abiturres tab abiturres if txg8==0 histogram abiturres if txg8==0,frequency tab abiturres if txg8==1 histogram abiturres if txg8==1, bin(25)frequency * twoway (kdensity abiturres if wave==1 & txg8==0 , area(100))(kdensity abiturres if wave==1 & txg8==1, area(100)), legend(label(1 "wave 1 G9") label(2 "wave 1 G8 old")) * graph export "${outDir}kdensity_abiturres_w1.pdf", replace twoway (kdensity mas2_sc1 if wave==2 & txg8==0, area(100) )(kdensity mas2_sc1 if wave==2 & txg8==1, area(100)), legend(label(1 "G9") label(2 "G8")) graph export "${outDir}kdensity_math.pdf", replace infoquery t38 t36 t41, alllang count if t38 == 1 // people who ever attended G8 alt list ID_t txg8 t36 t41 if t38 == 1, c ************************************************************ * 2) How do cohorts differ in age and gender composition ************************************************************ ********* * 2a)Age ********* fre tx8050y fre tx8050m *twoway (kdensity agey if wave==1 & txg8==0 , area(100))(kdensity agey if wave==1 & txg8==1, area(100)), legend(label(1 "wave 1 G9") label(2 "wave 1 G8 old")) *graph export "${outDir}kdensity_agey_w1.pdf", replace twoway (kdensity agey if wave==2 & txg8==0, area(100) )(kdensity agey if wave==2 & txg8==1, area(100)), legend(label(1 "G9") label(2 "G8")) graph export "${outDir}kdensity_agey.pdf", replace preserve sort wave txg8 by wave txg8: su agey by wave txg8: su agem restore ************ * 2b) Gender ************ preserve sort wave txg8 by wave txg8: tab tx80501 // in G8 old students are more likely to be girls //new G8 students' gender distribution is the same as previously in G9 restore ****************** *2c) Books at home ****************** fre t76 twoway (kdensity t76 if txg8==0, area(1293) )(kdensity t76 if txg8==1, area(1284)), legend(label(1 "G9") label(2 "G8")) twoway (kdensity t76 if txg8==0, area(100) )(kdensity t76 if txg8==1, area(100)), legend(label(1 "G9") label(2 "G8")) graph export "${outDir}kdensity_t76.pdf", replace ******************************************************************************************** * 3) Student satisfaction with a)life b) posessions c) health d) family e) friends f) school ********************************************************************************************* preserve sort wave txg8 by wave txg8: su t1a t1b t1c t1d t1e t1f restore **************************************************** *4) Historgrams of all interesting outcome variables **************************************************** //Englische Labels bei Bedarf einschalten /* la var t1a "Satisfaction - Life; 0 = completely unsatisfied, 10 = completely satisfied" la var t1f "Satisfaction - School; 0 = completely unsatisfied, 10 = completely satisfied" la var t5b "Sometimes, I have truble falling asleep due to school problems" la var t5f "I find scholastic requirements too demanding" la var t42f "Compared to others, my ability is lower" la var t54a "How often in the last 6 weeks did you suffer from nervousness?" la var t54l "How often in the last 6 weeks did you suffer from fatigue or exhaustion?" la var t54m "How often in the last 6 weeks did you suffer from the inability to relax?" la var t54o "How often in the last 6 weeks did you suffer from anger at everything?" la var t54v "How often in the last 6 weeks did you suffer from sadness?" */ /* foreach x in "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" { twoway (histogram t54x' if txg8==1,bfcolor(gs11) blcolor(gs11) percent by(female))(histogram t54x' if txg8==0,bfcolor(none) blcolor(gs5) percent), scheme(s2mono) legend(label(1 "G8") label(2 "G9")) xlabel( 1 "never" 2 "1-2 times" 3 "3-6 times" 4 "more than 6 times" , angle(45)) graph export "${outDir}histogram_t54x'.pdf", replace } foreach x in "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"{ twoway (histogram t5x' if txg8==1,bfcolor(gs11) blcolor(gs11) percent)(histogram t5x' if txg8==0,bfcolor(none) blcolor(gs5) percent), scheme(s2mono) legend(label(1 "G8") label(2 "G9")) xlabel( 1 "disagree" 2 "slightly disagree" 3 "slightly agree" 4 "agree" , angle(45)) graph export "${outDir}histogram_t5x'.pdf", replace } foreach x in "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" { twoway (histogram t42x' if txg8==1,bfcolor(gs11) blcolor(gs11) percent)(histogram t42x' if txg8==0,bfcolor(none) blcolor(gs5) percent), scheme(s2mono) legend(label(1 "G8") label(2 "G9")) xlabel( 1 "disagree" 2 "slightly disagree" 3 "slightly agree" 4 "agree" , angle(45)) graph export "${outDir}histogram_t42x'.pdf", replace } foreach x in "a" "b" "c" "d" "e" "f" { twoway (histogram t1x' if txg8==1,bfcolor(gs11) blcolor(gs11) percent)(histogram t1x' if txg8==0,bfcolor(none) blcolor(gs5) percent), scheme(s2mono) legend(label(1 "G8") label(2 "G9")) graph export "${outDir}histogram_t1x'.pdf", replace } ********************** *5) t-Tests ********************** set more off foreach x in "a" "b" "c" "d" "e" "f" { display "Question t1x'" *display "Wave 1" *qui: ttest t1x' if wave==1, by(txg8) *display "lower one-sided p-value: " as result r(p_l) display "Wave 2" qui: ttest t1x' if wave==2, by(txg8) display "lower one-sided p-value: " as result r(p_l) } */ preserve keep if wave==2 *la var t54e "Konzentrationsschwierigkeiten" *la var t54l "Müdigkeit, Erschöpfung" *la var t54m "Unfähigkeit zur Entspannung" ****************************************************************** *6) Make table with Summary Stats for all interesting variables ******************************************************************** local depVars stressscore healthscore t1f t1a //GSEscore local xlist txg8 female agey /*tutoring */ repeated sports /*music computer read*/ migration booksfew booksmed bookshig bookshig2 /*girlschool*/ *t5a t5b t5c t5d t5e t5f t5g t5h t5i t5j t5k t5l t5m t5n t5o /// *t42a t42b t42c t42d t42e t42f t42g t42h t42i t42j /// *sutex2 depVars' xlist', varlab min long saving("${outDir}descriptives.tex") replace ******************************* *6 b) Make table by wave and G8 ******************************* *estpost su t1a t1b t1c t1d t1f t42a t42b t42c t42d t42e t42f t42g t42h t42i t42j t5a t5b t5c t5d t5e t5f t5g t5h t5i t5j t5k t5l t5m t5n t5o t54* agem female t76 if wave==1 & txg8==0 *est store control *estpost su t1a t1b t1c t1d t1f t42a t42b t42c t42d t42e t42f t42g t42h t42i t42j t5a t5b t5c t5d t5e t5f t5g t5h t5i t5j t5k t5l t5m t5n t5o t54* agem female t76 if wave==1 & txg8==1 *est store treat estpost su depVars' xlist' est store all estpost su depVars' xlist' if txg8==0 est store controlpost estpost su depVars' xlist' if txg8==1 est store treatpost estpost su depVars' xlist' if female==0 est store male estpost su depVars' xlist' if female==1 est store female esttab all controlpost treatpost male female using "${outDir}descriptivesByG8.tex", /// replace /// stats(N, /// fmt(%18.0g) labels("Observations") /// layout("\multicolumn{1}{c}{@}""\multicolumn{1}{S}{@}")) /// f alignment(S S S S S) /// title(Descriptive statistics by treatment \label{tab:descriptG8}) /// mgroups( " ""\textbf{By reform}" "\textbf{By gender}", pattern(1 1 0 1 0) /// prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) /// mtitle("Pooled" "G9" "G8" "Male" "Female") /// refcat(stressscore "\textbf{Outcomes}" txg8 "\textbf{Student characteristics}" migration "\textbf{Parental background}" girlschool "\textbf{School}", nolabel) /// cells("mean(fmt(2))" "sd(fmt(2) par)" ) /// label booktabs collabels(none) /// /// long coeflabels() nonumber /// addnotes("\scriptsize \textit{Notes:} Data: NEPS $cohort$version wave 2. Own calculations.""\scriptsize std stands for z-standardized variables (over pooled sample)") *refcat(t1a "\emph{How satisfied are you with ...}" t42a "\emph{Self assessment}" t5a "\emph{Burdens}" t54a "\emph{Health Strains}", nolabel) /// eststo clear ******************************* *Descriptives new table ******************************* capt prog drop myttests program myttests, eclass version 13 syntax varlist [if] [in], by(varname) [ * ] marksample touse markout touse' by' tempname mu_1 mu_2 d d_se d_t d_p foreach var of local varlist { ttest var' if touse', by(by') options' mat mu_1' = nullmat(mu_1'), r(mu_1) mat mu_2' = nullmat(mu_2'), r(mu_2) mat d' = nullmat(d' ), r(mu_1)-r(mu_2) mat d_se' = nullmat(d_se'), r(se) mat d_t' = nullmat(d_t' ), r(t) mat d_p' = nullmat(d_p' ), r(p) } foreach mat in mu_1 mu_2 d d_se d_t d_p { mat coln mat'' = varlist' } tempname b V mat b' = mu_1'*0 mat V' = b''*b' eret post b' V' eret local cmd "myttests" foreach mat in mu_1 mu_2 d d_se d_t d_p { eret mat mat' = mat'' } end myttests stressscore healthscore t1f t1a txg8 female agey /*tutoring */ repeated sports /// /*music computer read*/ migration booksfew booksmed bookshig bookshig2 /*girlschool*/ , by(female) ereturn list esttab using "{outDir}diffgenders.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_p(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests stressscore healthscore t1f t1a txg8 female agey /*tutoring */ repeated sports /// /*music computer read*/ migration booksfew booksmed bookshig bookshig2 /*girlschool*/ , by(txg8) ereturn list esttab using "{outDir}diffg8.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_p(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) generate y = uniform() qui regress y stressscore healthscore t1f t1a if female==0, nocons estadd summ esttab using "{outDir}sudepvars.tex", /// replace /// cells("mean(fmt(2)) sd(fmt(2)) min max") /// nogap nonumber label /// f alignment(S S S S S) qui regress y stressscore healthscore t1f t1a if female==1, nocons estadd summ esttab using "{outDir}sudepvars.tex", /// append /// cells("mean(fmt(2)) sd(fmt(2)) min max") /// nogap nomtitle nonumber label /// f alignment(S S S S S) capt prog drop myttests /*! version 1.0.0 14aug2007 Ben Jann*/ program myttests, eclass version 13 syntax varlist [if] [in], by(varname) [ * ] marksample touse markout touse' by' tempname mu_1 mu_2 d d_se d_t d_p foreach var of local varlist { ttest var' if touse', by(by') options' mat mu_1' = nullmat(mu_1'), r(mu_1) mat mu_2' = nullmat(mu_2'), r(mu_2) mat d' = nullmat(d' ), r(mu_1)-r(mu_2) mat d_se' = nullmat(d_se'), r(se) mat d_t' = nullmat(d_t' ), r(t) mat d_p' = nullmat(d_p' ), r(p) } foreach mat in mu_1 mu_2 d d_se d_t d_p { mat coln mat'' = varlist' } tempname b V mat b' = mu_1'*0 mat V' = b''*b' eret post b' V' eret local cmd "myttests" foreach mat in mu_1 mu_2 d d_se d_t d_p { eret mat mat' = `mat'' } end myttests stdstress stdhealth t1f t1a, by(female) ereturn list esttab using "{outDir}diffdepvars.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests stdstress stdhealth t1f t1a if txg8==0, by(female) ereturn list esttab using "{outDir}diffdepvars.tex", append /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests stdstress stdhealth t1f t1a if txg8==1, by(female) ereturn list esttab using "{outDir}diffdepvars.tex", append /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests stressscore healthscore t1f t1a if txg8==0, by(magem) ereturn list esttab using "{outDir}agediffdepvars.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests stressscore healthscore t1f t1a if txg8==1, by(magem) ereturn list esttab using "{outDir}agediffdepvars.tex", append /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) /* myttests high*, by(txg8) esttab using "{outDir}diffsymptoms.tex", append /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))" ) /// nogap nonumber label /// f alignment(S S S S S) */ myttests female agey repeated sports migration booksfew booksmed bookshig bookshig2 girlschool, by(txg8) ereturn list esttab using "{outDir}diffxvars.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) restore use "{dataDir}mentalhealthnostd" , clear drop if txg8==1 & wave==1 myttests stressscore healthscore t1f t1a female agey repeated sports migration /// booksfew booksmed bookshig bookshig2 if txg8==0 & wave!=3, by(wave) ereturn list esttab using "{outDir}wavediffvars.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests stressscore healthscore t1f t1a female agey repeated sports migration /// booksfew booksmed bookshig bookshig2 if txg8==1 & wave!=1, by(wave) ereturn list esttab using "{outDir}wavediffvars-treated.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests stressscore healthscore t1f t1a female agey repeated sports migration /// booksfew booksmed bookshig bookshig2 if wave!=2, by(wave) ereturn list esttab using "{outDir}wavediffvars-control-treated.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests repeated if txg8==0, by(wave) esttab using "{outDir}wavediff-repeated.tex", replace /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests repeated if txg8==1, by(wave) esttab using "{outDir}wavediff-repeated.tex", append /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) myttests repeated if wave!=2, by(wave) esttab using "{outDir}wavediff-repeated.tex", append /// cells("mu_1(fmt(a3)) mu_2 d() d_t(star pvalue(d_p))") /// nogap nonumber label /// f alignment(S S S S S) // close log files *log close txt *log close smcl