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)



*Restricht to men (sex=1 -> Men, sex=2 women) aged 50-70. 
keep if sex==1 & age>=50 & age<=70

xtset pid syear

gen age2=age*age

*Generate indicator for being above 60
gen vr60=cond(age>=60 & age!=.,1,cond(age!=.,0,.))

*Generate treatment indicator based on birth cohort. 

gen vtreat=.
replace vtreat=0 if gebjahr<=1936
replace vtreat=1 if gebjahr>=1937 & gebjahr<=1941
replace vtreat=2 if gebjahr>=1942 & gebjahr<=1945
replace vtreat=3 if gebjahr>=1946 & gebjahr<=1948
replace vtreat=4 if gebjahr>=1949 & gebjahr<=1951
replace vtreat=5 if gebjahr>=1952




*Standardization of age


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", replace


*The coefficients on i.vr60##i.vtreat correspond to the results shown in Column 2 of Table 8, Panel A
xtreg retired i.vr60##i.vtreat i.vtreat##(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 A
margins, dydx(vr60) at(vtreat=(0(1)5)) noestimcheck 

log close

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

keep if vtreat==0

gen vtreat_placebo=.
replace vtreat_placebo=1 if gebjahr<=1933
replace vtreat_placebo=2 if gebjahr>=1934 & gebjahr<=1936

*The coefficients on i.vr60##i.vtreat_placebo correspond to the results shown in Column 2 of Table 7, Panel A
xtreg retired i.vr60##i.vtreat_placebo i.vtreat_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 A
margins, dydx(vr60) at(vtreat_placebo=(1(1)2)) noestimcheck 
log close

