cd "${output_path}\tmp\"

eststo clear
cap graph drop _all
use "Linked_data.dta", clear
set more off
keep if age>=25 & age<=40

*Generate discontinuities for fathers
gen vdisc60=cond((vage+0.001)>=(60+1/12),1,0)
replace vdisc60=cond((vage+0.001)>=(60+2/12),1,0) if vgebjahr==1952 & vgebmonat==1
replace vdisc60=cond((vage+0.001)>=(60+3/12),1,0) if vgebjahr==1952 & vgebmonat==2
replace vdisc60=cond((vage+0.001)>=(60+4/12),1,0) if vgebjahr==1952 & vgebmonat==3
replace vdisc60=cond((vage+0.001)>=(60+5/12),1,0) if vgebjahr==1952 & vgebmonat==4
replace vdisc60=cond((vage+0.001)>=(60+6/12),1,0) if vgebjahr==1952 & vgebmonat==5
replace vdisc60=cond((vage+0.001)>=(60+7/12),1,0) if vgebjahr==1952 & vgebmonat>=6 & vgebmonat<=12
replace vdisc60=cond((vage+0.001)>=(60+8/12),1,0) if vgebjahr==1953 
replace vdisc60=cond((vage+0.001)>=(60+9/12),1,0) if vgebjahr==1954
replace vdisc60=cond((vage+0.001)>=(60+10/12),1,0) if vgebjahr==1955
replace vdisc60=cond((vage+0.001)>=(60+11/12),1,0) if vgebjahr==1956
replace vdisc60=cond((vage+0.001)>=61,1,0) if vgebjahr==1957
 
gen vdisc65=cond((vage+0.001)>=(65+1/12),1,0)
replace vdisc65=cond((vage+0.001)>=(65+2/12),1,0) if vgebjahr==1947
replace vdisc65=cond((vage+0.001)>=(65+3/12),1,0) if vgebjahr==1948
replace vdisc65=cond((vage+0.001)>=(65+4/12),1,0) if vgebjahr==1949
replace vdisc65=cond((vage+0.001)>=(65+5/12),1,0) if vgebjahr==1950
replace vdisc65=cond((vage+0.001)>=(65+6/12),1,0) if vgebjahr==1951
replace vdisc65=cond((vage+0.001)>=(65+7/12),1,0) if vgebjahr==1952
replace vdisc65=cond((vage+0.001)>=(65+8/12),1,0) if vgebjahr==1953
replace vdisc65=cond((vage+0.001)>=(65+9/12),1,0) if vgebjahr==1954
replace vdisc65=cond((vage+0.001)>=(65+10/12),1,0) if vgebjahr==1955
replace vdisc65=cond((vage+0.001)>=(65+11/12),1,0) if vgebjahr==1956
replace vdisc65=cond((vage+0.001)>=66,1,0) if vgebjahr==1957



*Figure A1 for fathers
bys age: egen mvcretired=mean(vretired)



twoway (scatter mvcretired age if age>=25 & age<=40, msymbol(Oh)) (qfit vretired age if age>=25 & age<=40, lpattern("shortdash") lwidth("thick")) (lpoly vretired age if age>=17 & age<=40,  lwidth("thick") lpattern("longdash")), xtitle("Children's age") ytitle("Share of retired fathers") scheme(s1mono) legend(label(1 "Local averages") label(2 "Quadratic fit") label(3 "Nonparametric fit")) title("a. Paternal retirement by age of child") name(a1_fathers)





*Generate discontinuities for mothers

gen mdisc60=cond((mage+0.001)>=(60+1/12),1,0)
replace mdisc60=cond((mage+0.001)>=(60+2/12),1,0) if mgebjahr==1952 & mgebmonat==1
replace mdisc60=cond((mage+0.001)>=(60+3/12),1,0) if mgebjahr==1952 & mgebmonat==2
replace mdisc60=cond((mage+0.001)>=(60+4/12),1,0) if mgebjahr==1952 & mgebmonat==3
replace mdisc60=cond((mage+0.001)>=(60+5/12),1,0) if mgebjahr==1952 & mgebmonat==4
replace mdisc60=cond((mage+0.001)>=(60+6/12),1,0) if mgebjahr==1952 & mgebmonat==5
replace mdisc60=cond((mage+0.001)>=(60+7/12),1,0) if mgebjahr==1952 & mgebmonat>=6 & mgebmonat<=12
replace mdisc60=cond((mage+0.001)>=(60+8/12),1,0) if mgebjahr==1953 
replace mdisc60=cond((mage+0.001)>=(60+9/12),1,0) if mgebjahr==1954
replace mdisc60=cond((mage+0.001)>=(60+10/12),1,0) if mgebjahr==1955
replace mdisc60=cond((mage+0.001)>=(60+11/12),1,0) if mgebjahr==1956
replace mdisc60=cond((mage+0.001)>=61,1,0) if mgebjahr==1957
 
gen mdisc65=cond((mage+0.001)>=(65+1/12),1,0)
replace mdisc65=cond((mage+0.001)>=(65+2/12),1,0) if mgebjahr==1947
replace mdisc65=cond((mage+0.001)>=(65+3/12),1,0) if mgebjahr==1948
replace mdisc65=cond((mage+0.001)>=(65+4/12),1,0) if mgebjahr==1949
replace mdisc65=cond((mage+0.001)>=(65+5/12),1,0) if mgebjahr==1950
replace mdisc65=cond((mage+0.001)>=(65+6/12),1,0) if mgebjahr==1951
replace mdisc65=cond((mage+0.001)>=(65+7/12),1,0) if mgebjahr==1952
replace mdisc65=cond((mage+0.001)>=(65+8/12),1,0) if mgebjahr==1953
replace mdisc65=cond((mage+0.001)>=(65+9/12),1,0) if mgebjahr==1954
replace mdisc65=cond((mage+0.001)>=(65+10/12),1,0) if mgebjahr==1955
replace mdisc65=cond((mage+0.001)>=(65+11/12),1,0) if mgebjahr==1956
replace mdisc65=cond((mage+0.001)>=66,1,0) if mgebjahr==1957


*Figure A1 for mothers
bys age: egen mmcretired=mean(mretired)

twoway (scatter mmcretired age if age>=25 & age<=40, msymbol(Oh)) (qfit mretired age if age>=25 & age<=40, lpattern("shortdash") lwidth("thick") ) (lpoly mretired age if age>=17 & age<=40,  lwidth("thick") lpattern("longdash")), xtitle("Children's age") ytitle("Share of retired mothers") scheme(s1mono) legend(label(1 "Local averages") label(2 "Quadratic fit") label(3 "Nonparametric fit")) title("b. Maternal retirement by age of child") name(a1_mothers)

graph combine a1_fathers a1_mothers, altshrink scheme(s1mono)
graph export "${output_path}\Results\FigA1.tif", replace width(2400)
