Good evening -

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
as well as
Code:
forvalues
command without any success when it Comes to merging.
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)