Hi,
I want to execute a code for a list of variables, and part of the code only for a subset of the list (varA and varB)
I found an unelegant way to do this using an indicator `i', see below.
Does anyone know how I can directly use the positions of varA and varB in the local list?
* execute code1 for all variables ; execute code2 for varA and varB
local varlist var1 var2 varA varB var3
local i 0
foreach var of local varlist {
local i = `i' + 1
di "step `i' code1 "
if inlist(`i',3,4) {
di "code2 for `var'"
}
}
I want to execute a code for a list of variables, and part of the code only for a subset of the list (varA and varB)
I found an unelegant way to do this using an indicator `i', see below.
Does anyone know how I can directly use the positions of varA and varB in the local list?
* execute code1 for all variables ; execute code2 for varA and varB
local varlist var1 var2 varA varB var3
local i 0
foreach var of local varlist {
local i = `i' + 1
di "step `i' code1 "
if inlist(`i',3,4) {
di "code2 for `var'"
}
}
Comment