I'm currently working on generating cause specific SMRs for 20 different causes of death. Due to data privacy reasons, I have 20 different data files for the General Population that includes the mortality rates standardized to Age, sex, year, etc. I've been trying to loop over consecutive causes of death which correspond to merge file names (which are numbered 1-20)
I've tried the
Code:
foreach
Code:
forvalues
When I don't loop and instead manually include the numbers 1/20, I can obtain the SMRs.
forvalues i = 1/20 {
stset time_out2 , failure(cause_of_death==`i') id(id) origin(time s_date) exit(time td(30sep2011)) scale(365.25)
merge m:1 _year sex _age using "$dd\CoD data\`i'.dta", generate(_merge)
drop if _merge==2
drop _merge
di "SMR for CoD" `i'
strate, smr(rate)
}
Any insights would be greatly appreciated.
(Stata 14.2)
0 Response to Looping over merge files
Post a Comment