preserve
g age1=2013-a3a if a3a!=.
foreach i of numlist 2/9 {
g age`i'=a140`i'
}
foreach i of numlist 10/15 {
g age`i'=a14`i'
}
*
foreach i of numlist 1/15 {
g old`i' = 0
replace old`i' = 1 if age`i' >=60 & age`i'>=0 & age`i' !=.
g adult `i'=0
replace adult`i'=1 if age`i'<60 & age`i'>15 & age`i'!=.
g chd`i' = 0
replace chd`i' = 1 if age`i' <=15 & age`i'>=0 & age`i' !=.
}
egen num_old = rowtotal(old*)
egen num_chd = rowtotal(chd*)
egen num_adult =rowtotal(adult*)
egen num_all = num_old + num_adult +num_chd
drop age* old* chd* adult*
gen chdp = num_chd/ num_all
gen oldp= num_old/ num_all
restore