I have a programming challenge here, way over my head so far...but have been successfully creating variables using the NIS ICD_10 codes. I have currently 4 separate variables for 4 different types of obstetric hypertension: Gestational (GHYP), Mild/Moderate Pre-Eclampsia (PECLM), Severe Pre-Eclampsia (PECLS) and chronic and/or unspecified HTN (UHYP).
1) I need to combine them into 1 categorical variable, OHYP, with the above categories in order of severity, with most severe (PECLS) down to least (chronic/unspecified). 0 = PECLS, 1= PECLM, 2 = GHYP and 3 = UHYP. However...
2) the categories need to be mutually exclusive, so that if a person has two types of hypertension, it gets counted as only the MORE severe type. For example if someone has both PECLM and UHYP it gets coded as PECLM only.
Any suggestions of someone who could help me? Maybe it's an issue for a paid consultant? Or maybe one of you brilliant people can point me in the right direction? Thanks.
The code I used (multiple copy and pastes) to create each variable is as follows. This example uses the variable GHYP:
gen flag = 0
foreach v of varlist I10_DX1 - I10_DX40 {
icd10cm generate flag_`v' = `v', range (O131 O132 O133 O134 O135 O139)
replace flag = flag_`v' if flag_`v' > flag & flag_`v' != .
}
egen max1=rowmax(flag_I10_DX*)
tab max1, m
egen total1=rowtotal(flag_I10_DX*)
tab total1, m
gen codes1 =I10_DX1 if flag_I10_DX1 == 1
foreach v of varlist I10_DX1 - I10_DX40 {
replace codes1 = `v"' if flag_`v' == 1
}
tab codes1, m
tab codes1, m
rename codes1 codes_GHYP
rename flag GHYP
rename max1 max_GHYP
rename total1 total_GHYP
drop flag_I10_DX*
tab codes_GHYP, m
tab GHYP,m
tab max_GHYP, m
1) I need to combine them into 1 categorical variable, OHYP, with the above categories in order of severity, with most severe (PECLS) down to least (chronic/unspecified). 0 = PECLS, 1= PECLM, 2 = GHYP and 3 = UHYP. However...
2) the categories need to be mutually exclusive, so that if a person has two types of hypertension, it gets counted as only the MORE severe type. For example if someone has both PECLM and UHYP it gets coded as PECLM only.
Any suggestions of someone who could help me? Maybe it's an issue for a paid consultant? Or maybe one of you brilliant people can point me in the right direction? Thanks.
The code I used (multiple copy and pastes) to create each variable is as follows. This example uses the variable GHYP:
gen flag = 0
foreach v of varlist I10_DX1 - I10_DX40 {
icd10cm generate flag_`v' = `v', range (O131 O132 O133 O134 O135 O139)
replace flag = flag_`v' if flag_`v' > flag & flag_`v' != .
}
egen max1=rowmax(flag_I10_DX*)
tab max1, m
egen total1=rowtotal(flag_I10_DX*)
tab total1, m
gen codes1 =I10_DX1 if flag_I10_DX1 == 1
foreach v of varlist I10_DX1 - I10_DX40 {
replace codes1 = `v"' if flag_`v' == 1
}
tab codes1, m
tab codes1, m
rename codes1 codes_GHYP
rename flag GHYP
rename max1 max_GHYP
rename total1 total_GHYP
drop flag_I10_DX*
tab codes_GHYP, m
tab GHYP,m
tab max_GHYP, m
Comment