Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Coding challenge: creating categorical variable using NIS ICD codes

    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

  • #2
    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).
    The important aspect is to show these variables using dataex. Assuming they are indicators, you can have:

    Code:
    clear
    input float(patientid light mild heavy severe)
    1 0 1 0 0 0
    2 1 0 1 0 0
    3 1 1 0 1 1
    4 0 0 0 1 0
    5 1 0 0 0 0
    end
    
    gen wanted= max(light*1, mild*2, heavy*3, severe*4)

    Res.:

    Code:
    . l
    
         +---------------------------------------------------+
         | patien~d   light   mild   heavy   severe   wanted |
         |---------------------------------------------------|
      1. |        1       0      1       0        0        2 |
      2. |        2       1      0       1        0        3 |
      3. |        3       1      1       0        1        4 |
      4. |        4       0      0       0        1        4 |
      5. |        5       1      0       0        0        1 |
         +---------------------------------------------------+

    Post back with a data example if the above is not helpful.

    Comment


    • #3
      Hi,
      I am trying to startify NIS data based on number of procedures performed per year. Can you please guide which command should I use.
      Thanks

      Comment


      • #4
        Originally posted by Jasmeet Kaur View Post
        Hi,
        I am trying to startify NIS data based on number of procedures performed per year. Can you please guide which command should I use.
        Thanks
        Per my other comment, please start a new thread. It’s considered impolite and off-topic to hijack old threads with essentially a different question.

        Comment


        • #5
          Note: I solved my above question using the max1 variable. Thanks.

          Comment

          Working...
          X