Greetings,

A sample data set for my problem is shown below. I am trying to generate few new variables where the new variable is 1 if anywhere in the row we have ICD 9 code range of V09.00-V09.91.

I was able to use the following command when I only have one or two code but how do I generate a new variable where it is a range such as 038.0-038.9 but as a string variable or a range such as V09.00-V09.91 which is alphanumeric? To reiterate, I want to create (1) a new variable = 1 if anywhere in that row there is anything between 038.0 to 038.9 (listed as string) and (2) another new variable = 1 if anywhere in that row there is anything between ICD 9 code of V09.00 to V09.91. I have DCODE1 DCODEDES1...all the way up to DCODE43 DCODEDES43. Any guidance is highly appreciated.

egen Sepsis = rany(DCODE*), c(@ =="995.91" | @=="995.92")

. dataex INC_KEY DCODE1 DCODEDES1 DCODE2 DCODEDES2 DCODE3 DCODEDES3 in 1/15

----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long INC_KEY str6 DCODE1 str114 DCODEDES1 str6 DCODE2 str114 DCODEDES2 str6 DCODE3 str114 DCODEDES3
11000000 "873.0"  "Open wound of scalp"                            "873.40" "Open wound of face unspecified site"         ""       ""                                 
11000001 "891.0"  "Open wound of knee, leg, or ankle"              ""       ""                                            ""       ""                                 
11000002 "873.0"  "Open wound of scalp"                            "872.00" "Open wound of external ear unspecified site" "922.2"  "Contusion of adominal wall"       
11000003 "802.26" "Fx symphysis mandible body, closed"             "873.63" "Open wound of tooth"                         "802.22" "Subcondylar Fx, mandible, closed" 
11000004 "813.82" "Fx of unla closed unspecified"                  "812.21" "Fx humerus shaft closed"                     "873.0"  "Open wound of scalp"              
11000005 "864.03" "Liver laceration moderate closed"               ""       ""                                            ""       ""                                 
11000006 "802.0"  "Nasal bone fx, closed"                          "854.02" "Intracranial injury NOS closed brief loc"    "922.2"  "Contusion of adominal wall"       
11000007 "860.0"  "Traumatic pneumothorax, closed"                 ""       ""                                            ""       ""                                 
11000008 "807.02" "Rib fx closed, two ribs"                        "910.0"  "Abrasion face, neck or scalp"                "911.0"  "Abrasion of trunk"                
11000009 "873.44" "Open wound of jaw"                              "830.0"  "Dislocation of jaw closed"                   "802.6"  "Fx orbital floor, closed"         
11000010 "863.40" "Injury to colon unspecified site injury closed" ""       ""                                            ""       ""                                 
11000011 "873.41" "Open wound of cheek"                            "872.01" "Open wound of external ear pinna or auricle" "911.0"  "Abrasion of trunk"                
11000012 "826.1"  "Fx one or more phalanges of foot open"          "891.0"  "Open wound of knee, leg, or ankle"           ""       ""                                 
11000013 "911.0"  "Abrasion of trunk"                              "860.0"  "Traumatic pneumothorax, closed"              "780.09" "Alteration of consciousness other"
11000014 "910.0"  "Abrasion face, neck or scalp"                   "924.01" "Contusion of hip"                            "873.43" "Open wound of lip"                
end
------------------ copy up to and including the previous line ------------------

Listed 15 out of 722836 observations


Thank you,
Priyanka