Hello, I have a big dataset and I am trying to analyse children with all congenital heart diseases(CHD). ICD9 code is "745.x" to "747.x ". There are 25 columns of diagnosis from DX1-DX25. I generated variable CHD using the following codes.
gen CHD=0
foreach var of varlist DX1-DX25 {
replace CHD=1 if (substr(`var',1,3) >= "745" & substr(`var',1,3) <= "747")
}
label var CHD "Congenital Heart Diseases"
I would like to remove the following codes from the previous CHD group- Excluding :" 746.86", "747.32", "747.6x"," 747.8x"
I tried to a couple of ways, but it threw me errors .
gen chd=0
forvalues j=1/25{
replace chd=1 if inlist(DX`j', >="745" & <"748" )
replace chd=0 if inlist(DX`j', "746.86", "747.32")
replace chd=0 if inlist(substr(DX,1,5),"747.6","747.8")
}
label variable chd " congenital heart diseases"
I also tried but that threw error as well:
gen chd=0
foreach var of varlist DX1-DX25 {
replace chd=1 if (substr(`var',1,3) >= "745" & substr(`var',1,3) <= "747")
replace chd=0 if (substr(`var',1,5)= "747.6","747.8") & (substr(`var',1,6)= "746.86","747.32")
}
label variable chd " congenital heart diseases"
I really appreciate your help.
0 Response to Excluding certain items/variables from query
Post a Comment