cd "${output_path}\tmp\"

use "Linked_data.dta", clear

*Restrict to observations where the father is 50-70 and the child is 25-40
keep if vage>=50 & vage<=70 & age>=25 & age<=40

xtset pid syear

gen fbirth=f.birth
gen age2=age*age
gen vage2=vage*vage

*Indicator whether the father is above 60
gen vr60=cond(vage>=60 & vage!=.,1,cond(vage!=.,0,.))

*Reform indicators based on father's birthyear.
gen vtreat=.
replace vtreat=0 if vgebjahr<=1936
replace vtreat=1 if vgebjahr>=1937 & vgebjahr<=1941
replace vtreat=2 if vgebjahr>=1942 & vgebjahr<=1945
replace vtreat=3 if vgebjahr>=1946 & vgebjahr<=1948
replace vtreat=4 if vgebjahr>=1949 & vgebjahr<=1951
replace vtreat=5 if vgebjahr>=1952



*Standardizing father's age
foreach var of varlist vage vage2{
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 A
xtreg fbirth i.vr60##i.vtreat i.vtreat##(c.vage_sd c.vage2_sd) age age2  i.month i.syear ,fe cluster(pid)
*The estimated margins correspond to the results shown in Column 3 of Table 8, Panel A
margins, dydx(vr60) at(vtreat=(0(1)5)) noestimcheck 


log close


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


keep if vtreat==0


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

*The coefficients on i.vr60##i.vtreat_placebo correspond to the results shown in Column 4 of Table 7, Panel A
xtreg fbirth i.vr60##i.vtreat_placebo i.vtreat_placebo##(c.vage_sd c.vage2_sd) age age2  i.month i.syear ,fe cluster(pid)
*The estimated margins correspond to the results shown in Column 3 of Table 7, Panel A
margins, dydx(vr60) at(vtreat_placebo=(1(1)2)) noestimcheck 

log close
