cd "${output_path}\tmp\"

use "Linked_data.dta", clear

keep if mage>=50 & mage<=70 & age>=25 & age<=40

xtset pid syear
gen fbirth=f.birth
gen age2=age*age
gen mage2=mage*mage


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

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



foreach var of varlist mage mage2{
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 4 of Table 8, Panel B

xtreg fbirth age age2 i.mr60##i.mtreat i.mtreat##(c.mage_sd c.mage2_sd)   i.month i.syear ,fe cluster(pid)
*The estimated margins correspond to the results shown in Column 3 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 mgebjahr<=1936
replace mtreat_placebo=2 if mgebjahr>=1937 & mgebjahr<=1939

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

xtreg fbirth age age2 i.mr60##i.mtreat_placebo i.mtreat_placebo##(c.mage_sd c.mage2_sd)   i.month i.syear ,fe cluster(pid)
*The estimated margins correspond to the results shown in Column 3 of Table 7, Panel B
margins, dydx(mr60) at(mtreat_placebo=(1(1)2)) noestimcheck 

log close