Good morning,
I'm working with a data file including variables from icd_nd1 - icd_nd89. I want to write a loop, which generates a new var laestring=1, for each var that from the varlist icd_nd1 - icd_nd89 that includes "I260" or "I269", no matter which letters/numebers are following. Somehow my code does not work, does somebody have an idea? Thank you very much for your help!
foreach var of varlist icd_nd1-icd_nd89 {
gen laestring`var' = 1 if strpos(`var', "I260") | strpos(`var', "I269")
}
foreach var of varlist laestringicd_nd* {
recode `var' . = 0
}
gen laestring = 0
replace laestring = 1 if laestringicd_nd1-laestringicd_nd89 != 0
drop laestringicd_nd1-laestringicd_nd89
codebook laestring
label variable laestring "0 = no LAE 1 = LAE"
Example of the Data file
icd_nd1 icd_nd2 icd_nd3 icd_nd4 icd_nd5 icd_nd6
I1000 E780 G8203 D62 K638
C499 H360 J4412
J3800 E782 B962
C679 R11 Z922
E871 R11 I700
I'm working with a data file including variables from icd_nd1 - icd_nd89. I want to write a loop, which generates a new var laestring=1, for each var that from the varlist icd_nd1 - icd_nd89 that includes "I260" or "I269", no matter which letters/numebers are following. Somehow my code does not work, does somebody have an idea? Thank you very much for your help!
foreach var of varlist icd_nd1-icd_nd89 {
gen laestring`var' = 1 if strpos(`var', "I260") | strpos(`var', "I269")
}
foreach var of varlist laestringicd_nd* {
recode `var' . = 0
}
gen laestring = 0
replace laestring = 1 if laestringicd_nd1-laestringicd_nd89 != 0
drop laestringicd_nd1-laestringicd_nd89
codebook laestring
label variable laestring "0 = no LAE 1 = LAE"
Example of the Data file
icd_nd1 icd_nd2 icd_nd3 icd_nd4 icd_nd5 icd_nd6
I1000 E780 G8203 D62 K638
C499 H360 J4412
J3800 E782 B962
C679 R11 Z922
E871 R11 I700
Comment