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

must be a valid name for an estimation set. Valid names for estimation sets cannot be simply numbers. They are subject to the same constraints as variable names: the first character must be a letter or underscore (_) character. So change -eststo `i'`j' :- to something like -eststo r`i'`j' :-. (It doesn't have to be r, that's just a suggestion because it evokes "results." But it can be any letter(s) or underscore.)
Comment