graph drop _all



cd "${output_path}\tmp\"

eststo clear
use "Linked_data.dta", clear




sort pid syear
xtset pid syear
gen fbirth=f.birth

gen hschool=cond(pgpsbil==3 | pgpsbil==4,1,cond(pgpsbil==.,.,0))
gen vhschool=cond(vpgpsbil==3 | vpgpsbil==4,1,cond(vpgpsbil==.,.,0))
gen mhschool=cond(mpgpsbil==3 | mpgpsbil==4,1,cond(mpgpsbil==.,.,0))
gen polinterest=cond(politics==1 | politics==2,1,cond(politics==3 | politics==4,0,.))
gen urban=cond(regtyp==1,1,cond(regtyp==2,0,.))
recode sex (2=0)
gen vmig=cond(vmigback==2 | vmigback==3,1,cond(vmigback==1,0,.))
gen mmig=cond(mmigback==2 | mmigback==3,1,cond(mmigback==1,0,.))










keep if age>=25 & age<=40
preserve
keep if vage>=50 & vage<=70



gen vdisc60=60+1/12
replace vdisc60=60+2/12 if vgebjahr==1952 & vgebmonat==1
replace vdisc60=60+3/12 if vgebjahr==1952 & vgebmonat==2
replace vdisc60=60+4/12 if vgebjahr==1952 & vgebmonat==3
replace vdisc60=60+5/12 if vgebjahr==1952 & vgebmonat==4
replace vdisc60=60+6/12 if vgebjahr==1952 & vgebmonat==5
replace vdisc60=60+7/12 if vgebjahr==1952 & vgebmonat>=6 & vgebmonat<=12
replace vdisc60=60+8/12 if vgebjahr==1953 
replace vdisc60=60+9/12 if vgebjahr==1954
replace vdisc60=60+10/12 if vgebjahr==1955
replace vdisc60=60+11/12 if vgebjahr==1956
replace vdisc60=61 if vgebjahr==1957
 



gen vage_run=vage-vdisc60



gen vage_int=round(vage,1)
gen vage_run_int=round(vage_run,1)
gen east1989=cond(loc1989==1,1,cond(loc1989==2 | loc1989==3,0,.))

sort pid syear
bys vage_int: egen hschool_fmean=mean(hschool)
bys vage_int: egen sex_fmean=mean(sex)
bys vage_int: egen east_fmean=mean(east1989)
bys vage_int: egen rel_fmean=mean(chris_rel)
bys vage_int: egen pgbilzeit_fmean=mean(pgbilzeit)


twoway  (qfitci hschool vage_run if vage_run<0, fintensity(inten10)) (qfitci hschool vage_run if vage_run>=0, fintensity(inten10)) (scatter hschool_fmean vage_run_int, lwidth("thin")), ///
xtitle("Father's age centered around threshold") ytitle("% children with high school degree") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("A. High school degree") name(highschool)

twoway (qfitci sex vage_run if vage_run<0, fintensity(inten10)) (qfitci sex vage_run if vage_run>=0, fintensity(inten10)) (scatter sex_fmean vage_run_int, lwidth("thin")) , ///
xtitle("Father's age centered around threshold") ytitle("% daughters") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("B. Gender ratio") name(sex)


twoway (qfitci chris_rel vage_run if vage_run<0, fintensity(inten10)) (qfitci chris_rel vage_run if vage_run>=0, fintensity(inten10)) (scatter rel_fmean vage_run_int, lwidth("thin")) , ///
xtitle("Father's age centered around threshold") ytitle("% following Christian religion") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("C. Christian religon") name(rel)

twoway (qfitci pgbilzeit vage_run if vage_run<0, fintensity(inten10)) (qfitci pgbilzeit vage_run if vage_run>=0, fintensity(inten10)) (scatter pgbilzeit_fmean vage_run_int, lwidth("thin")) , ///
xtitle("Father's age centered around threshold") ytitle("Years of education") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("D. Years of education") name(bilzeit)



grc1leg highschool sex rel bilzeit , altshrink title("Continuity of covariates - Children and father's age") scheme(s1mono)
graph export "${output_path}\Results\FigA7_A.tif", replace width(2400) 
graph drop _all

restore
keep if mage>=50 & mage<=70


gen mdisc60=60+1/12
replace mdisc60=60+2/12 if mgebjahr==1952 & mgebmonat==1
replace mdisc60=60+3/12 if mgebjahr==1952 & mgebmonat==2
replace mdisc60=60+4/12 if mgebjahr==1952 & mgebmonat==3
replace mdisc60=60+5/12 if mgebjahr==1952 & mgebmonat==4
replace mdisc60=60+6/12 if mgebjahr==1952 & mgebmonat==5
replace mdisc60=60+7/12 if mgebjahr==1952 & mgebmonat>=6 & mgebmonat<=12
replace mdisc60=60+8/12 if mgebjahr==1953 
replace mdisc60=60+9/12 if mgebjahr==1954
replace mdisc60=60+10/12 if mgebjahr==1955
replace mdisc60=60+11/12 if mgebjahr==1956
replace mdisc60=61 if mgebjahr==1957
 


gen mage_run=mage-mdisc60
gen east1989=cond(loc1989==1,1,cond(loc1989==2 | loc1989==3,0,.))


gen mage_int=round(mage,1)
gen mage_run_int=round(mage_run,1)
bys mage_int: egen hschool_mmean=mean(hschool)
bys mage_int: egen sex_mmean=mean(sex)
bys mage_int: egen east_mmean=mean(east1989)
bys mage_int: egen rel_mmean=mean(chris_rel)
bys mage_int: egen pgbilzeit_mmean=mean(pgbilzeit)


twoway  (qfitci hschool mage_run if mage_run<0, fintensity(inten10)) (qfitci hschool mage_run if mage_run>=0, fintensity(inten10)) (scatter hschool_mmean mage_run_int, lwidth("thin")), ///
xtitle("Mother's age centered around threshold") ytitle("% children with high school degree") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("A. High school degree") name(highschool)


twoway (qfitci sex mage_run if mage_run<0, fintensity(inten10)) (qfitci sex mage_run if mage_run>=0, fintensity(inten10)) (scatter sex_mmean mage_run_int, lwidth("thin")) , ///
xtitle("Mother's age centered around threshold") ytitle("% daughters") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("B. Gender ratio") name(sex)


twoway (qfitci chris_rel mage_run if mage_run<0, fintensity(inten10)) (qfitci chris_rel mage_run if mage_run>=0, fintensity(inten10)) (scatter rel_mmean mage_run_int, lwidth("thin")) , ///
xtitle("Mother's age centered around threshold") ytitle("% following Christian religion") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("C. Christian religion") name(rel)

twoway (qfitci pgbilzeit mage_run if mage_run<0, fintensity(inten10)) (qfitci pgbilzeit mage_run if mage_run>=0, fintensity(inten10)) (scatter pgbilzeit_mmean mage_run_int, lwidth("thin")) , ///
xtitle("Mother's age centered around threshold") ytitle("Years of education") scheme(s1mono) legend(label(5 "Mean") label(2 "Local polynomial fit")  order(5 2)) title("D. Years of education") name(bilzeit)




grc1leg highschool sex rel bilzeit, altshrink title("Continuity of covariates - Children and mother's age") scheme(s1mono)
graph export "${output_path}\Results\FigA7_B.tif", replace width(2400) 

