I m wondering if there is a way in stata to use arrays ( like in sas) to search through multiple icd codes.
the data i have is in this format: (each line is a hospitalization)
id | date | diag1 | diag2 | diag3 | diag4 | diag5 | |||
1 | 20jan2018 | t40.0 | |||||||
1 | 16oct2018 | t40.6 | |||||||
2 | 04apr2018 | t40.3 |
i would like to identify all of the diagnosis codes that are t40.0-t40.6 such that if present, then i can create a variable pat_diagnosis=1, if absent then pat_diagnosis=0
with sas we set up an array , but with stata, i can only think of using for loops like this:
gen pat_diagnosis=0
forv i=1/5{
replace pat_diagnosis`i'=1 if diag`i'>= "t40.0" & diag`i'<="T40.6"
}
any thoughts on a better way than this?
thanks in advance
vishal
0 Response to arrays in stata?
Post a Comment