I'm having trouble with a loop. I'm working on medical data and I want to create a flag for a category of diagnoses. This diagnosis category has 2,000+ codes (alpha-numeric strings) associated with it that I have store in a separate excel file. I want to bring these in and use them in a loop as part of my replace function which, itself, is in a loop. But i get an error telling me that the first diagnosis code is invalid. I assume this is a problem with how I am nesting the loops, or even something simple as how string variables are used here. Here is the malfunctioning code:
levelsof codes, local(levels)
gen category = .
foreach x of varlist diagnosiscode2-diagnosiscode15{
foreach y of local levels
replace category = 1 if `x' = `y'
}
}
Any ideas on how to build this properly?
-LM
levelsof codes, local(levels)
gen category = .
foreach x of varlist diagnosiscode2-diagnosiscode15{
foreach y of local levels
replace category = 1 if `x' = `y'
}
}
Any ideas on how to build this properly?
-LM
Comment