// Creates w_npens_dv - Number of people over pensionable age in household // INPUT FILE - w_indall.dta // OUTPUT FILE - w_npens_dv.dta // WRITE FILEPATH WHERE YOU HAVE DOWNLOADED THE DATA global in "" // WRITE FILEPATH WHERE YOU WOULD LIKE TO SAVE THE OUTPUT FILE global outpath "" // 1 is for BHPS, 2 is for UKHLS global cohort "2" // INCLUDE WAVE LETTERS FOR THE WAVES NEEDED global waves a b c d e f g h i j k l **** Don’t make changes after this point **** foreach w of global waves { global wave "`w'_" global num=strpos("abcdefghijklmnopqrstuvwxyz","`w'") global dta "" global waveno=$num global inpath "${in}/bhps_w${num}" if $cohort==2 { global waveno=$num+18 global inpath "${in}/ukhls" } use "${inpath}/${wave}indall${dta}", clear /*-------------ORIGINAL CODE--------------*/ * gen number of people over pensionable age in household $_NPENS_DV recode ${wave}age_dv (-11/-1=.) gen pens_=(((${wave}sex_dv==1 & ${wave}age_dv>=65) | (${wave}sex_dv==2 & ${wave}age_dv>=60)) & ${wave}age_dv<.) bys ${wave}hidp: egen ${wave}npens_dv=sum(pens_) lab def ${wave}npens_dv -9 "missing" 0"none", replace lab val ${wave}npens_dv ${wave}npens_dv tab ${wave}npens_dv lab var ${wave}npens_dv "# of people over pensionable age in hh" bysort ${wave}hidp: keep if _n==1 keep ${wave}hidp ${wave}npens_dv save "${outpath}/${wave}npens_dv", replace }