Hi,
I am new to Stata. I am trying to use the foreach command to go over a list of variables (5) to create a new variable with value of 1 if any of the 40 variables contains a specific string variable (I12 for example)
This is the code I am using, but it only goes over the first variable and returns the results without going over the rest of the variables, what am I doing wrong here?
foreach i of varlist (variable1 - variable5) {
gen kin=1 if `i'==3,
}
Thank you for your help
I am new to Stata. I am trying to use the foreach command to go over a list of variables (5) to create a new variable with value of 1 if any of the 40 variables contains a specific string variable (I12 for example)
This is the code I am using, but it only goes over the first variable and returns the results without going over the rest of the variables, what am I doing wrong here?
foreach i of varlist (variable1 - variable5) {
gen kin=1 if `i'==3,
}
Thank you for your help
Comment