Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Need to simplfy the code for ICD9

From   Kieran McCaul <>
To   "" <>
Subject   st: RE: Need to simplfy the code for ICD9
Date   Tue, 28 May 2013 13:02:44 +0800


I don't use the icd9 program when I'm working with ICD-coded disease variables, mainly because the data I work with spans over 40 years and so ICD8, ICD9, and ICD10 codes are used.
I also tend not to worry about the number of lines of code when I'm dealing with ICD codes: readability is more important.
I have 21 diagnosis variables, diagcode1 to diagcode21, all strings.  
The following flags cases of diabetes or diabetes-related conditions.

gen byte diabdiag_flag=0
forvalues i=1/22  {
	qui replace diabdiag_flag=1 if  substr(diagcode`i',1,3)=="250"  /* 250   Diabetes mellitus */
	qui replace diabdiag_flag=1 if sep_date >= mdy(7,1,1999) & ///
	            (substr(diagcode`i',1,3)>="E10" & ///
	             substr(diagcode`i',1,3)<="E14")                    /* (E10-E14) Diabetes mellitus */

gen byte diabcond_flag=0
forvalues i=1/22  {
	qui replace diabcond_flag=1 if  sep_date >= mdy(1,1,1979) & ///
	            (substr(diagcode`i',1,5)=="357.2" | ///          /* 357.2  Polyneuropathy in diabetes */
	             substr(diagcode`i',1,5)=="362.0" | ///          /* 362.0  Diabetic retinopathy       */
	             substr(diagcode`i',1,6)=="366.41")              /* 366.41 Diabetic cataract          */
	qui replace diabcond_flag=1 if  sep_date >= mdy(7,1,1999) & ///
	            (substr(diagcode`i',1,5)=="H28.0" | ///         /* H28.0  Diabetic cataract          */
	             substr(diagcode`i',1,5)=="H36.0" | ///         /* H36.0  Diabetic retinopathy       */
	             substr(diagcode`i',1,5)=="M14.2" | ///         /* M14.2  Diabetic arthropathy       */
	             substr(diagcode`i',1,5)=="N08.3")              /* N08.3  Glomerular disorders in diabetes mellitus */

-----Original Message-----
From: [] On Behalf Of Michael Stewart
Sent: Tuesday, 28 May 2013 6:13 AM
To: statalist
Subject: st: Need to simplfy the code for ICD9

I am trying to find an efficient code for working with ICD9 doagnosis codes

At present: To create a variable (1/0) which denotes if there is/are
ICD9 codes for a disease in the ICD9 section of the database  , I am
using a 4 step code  as folows


foreach x in SDX1 SDX2 SDX3 SDX4 SDX5 SDX6 SDX7 SDX8{
icd9 generate disease_`x'= `x', range(296* 300* 309.1 311)

egen disease_1=rowmax(disease_SDX1 disease_SDX2 disease_SDX3
disease_SDX4 disease_SDX5 disease_SDX6 disease_SDX7 disease_SDX8)

egen disease=max(disease_1)

drop disease_SDX*  disease_1

Is there a more elegant, code that can be executed in lesser number of steps .

Please help me .

Thank you ,
Yours Sincerely,
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index