cd "${output_path}\tmp\"


*Tables 7 and 8 (retirement outcome) are estimated based on parent level data, rather than children-parent level data. Therefore, we use individual-level observation (dataset child.dta) and restrict observations to fathers and mothers for whom we also observe the child in our main estimation sample.

use "Linked_data.dta", clear
keep if age>=25 & age<=40
keep vnr
duplicates drop
rename vnr pid
save "IDs_fathers.dta", replace

use "Linked_data.dta", clear
keep if age>=25 & age<=40
keep mnr
duplicates drop
rename mnr pid
save "IDs_mothers.dta", replace

append using "IDs_fathers.dta"

save "Complete_IDs_parents.dta", replace

graph drop _all
use "child.dta", replace
merge m:1 pid using "Complete_IDs_parents.dta", keep(match) gen(merge_childsample)

keep if sex==2 & age>=50 & age<=70

xtset pid syear

gen age2=age*age


gen mr60=cond(age>=60 & age!=.,1,cond(age!=.,0,.))

gen mtreat=.
replace mtreat=0 if gebjahr<=1939
replace mtreat=1 if gebjahr>=1940 & gebjahr<1945
replace mtreat=2 if gebjahr>=1945 & gebjahr<1952
replace mtreat=3 if gebjahr>1952



foreach var of varlist age age2{
sum `var'
gen `var'_sd=(`var'-r(mean))/r(sd)
}


cap log close
set logtype text

log using "${output_path}\Results\Table8.txt", append


*The coefficients on i.vr60##i.vtreat correspond to the results shown in Column 2 of Table 8, Panel B

xtreg retired i.mr60##i.mtreat i.mtreat##(c.age_sd c.age2_sd)  i.month i.syear ,fe cluster(pid)
*The estimated margins correspond to the results shown in Column 1 of Table 8, Panel B
margins, dydx(mr60) at(mtreat=(0(1)3)) noestimcheck 

log close

log using "${output_path}\Results\Table7.txt", append



keep if mtreat==0

gen mtreat_placebo=.
replace mtreat_placebo=1 if gebjahr<=1936
replace mtreat_placebo=2 if gebjahr>=1937 & gebjahr<=1939

*The coefficients on i.vr60##i.vtreat_placebo correspond to the results shown in Column 2 of Table 7, Panel B

xtreg retired i.mr60##i.mtreat_placebo i.mtreat_placebo##(c.age_sd c.age2_sd)  i.month i.syear ,fe cluster(pid)
*The estimated margins correspond to the results shown in Column 1 of Table 7, Panel B
margins, dydx(mr60) at(mtreat_placebo=(1(1)2)) noestimcheck 
log close
