I am trying to make a foreach search through a variable list easier and would really appreciate some help.
I'm currently using STATA 14 on windows.
I'm using an administrative database that contains ICD-9 diagnostic codes, numeric, that are saved as string variables. I have tried to destring but STATA won't allow me to.
They are contained within variables dx1-dx15 and have a three number core followed by up to two more numbers that further specify the type of diagnosis.
For example it could be 434, 4341, 43412, etc...
Sometimes I search for a specific codes and that works fine but I am asking for help in figuring out a way to search for ALL codes starting with 434 (as an example) and followed by whatever numbers. That way I wouldn't have to specify every number.
My typical search goes something like this:
gen diagnosis=0
foreach var of varlist dx1-dx15 {
replace diagnosis=1 if (`var'=="434"|`var'=="4340"|`var'=="43401"......)
}
I would appreciate any help in making that process easier!
Thanks in advance!
I'm currently using STATA 14 on windows.
I'm using an administrative database that contains ICD-9 diagnostic codes, numeric, that are saved as string variables. I have tried to destring but STATA won't allow me to.
They are contained within variables dx1-dx15 and have a three number core followed by up to two more numbers that further specify the type of diagnosis.
For example it could be 434, 4341, 43412, etc...
Sometimes I search for a specific codes and that works fine but I am asking for help in figuring out a way to search for ALL codes starting with 434 (as an example) and followed by whatever numbers. That way I wouldn't have to specify every number.
My typical search goes something like this:
gen diagnosis=0
foreach var of varlist dx1-dx15 {
replace diagnosis=1 if (`var'=="434"|`var'=="4340"|`var'=="43401"......)
}
I would appreciate any help in making that process easier!
Thanks in advance!
Comment