Announcement

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

  • Checking for misdiagnosis using ICD10

    Hi,

    Having a large data, I need to check if any of males misdiagnosed by assigned female-specific ICD10 codes and vice versa. I tried but did not figure it out. I am thinking about local command or macros but not sure if it is the right one or how. Is it okay to enter all males codes as a new variable and similarly for females, because when I did it produced false results? or should the list be in the memory (virtual) without including it in the raw data?

    Here is a sample of the data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte Sex str4 Diag1_code
    2 "O342"
    1 "R104"
    1 "K358"
    1 "J931"
    2 "O249"
    1 "I10" 
    2 "N202"
    1 "I249"
    1 "K649"
    2 "O269"
    2 "O800"
    1 "I501"
    2 "M480"
    2 "C509"
    1 "Q211"
    1 "A239"
    2 "N133"
    2 "N939"
    2 "O800"
    2 "I64" 
    2 "C543"
    2 "J988"
    2 "O800"
    1 "N210"
    2 "J459"
    1 "A239"
    2 "O034"
    1 "C169"
    2 "O800"
    2 "R104"
    1 "E111"
    1 "J189"
    2 "J069"
    1 "I739"
    1 "K409"
    1 "K566"
    2 "C509"
    1 "U071"
    1 "E114"
    2 "I214"
    2 "O800"
    2 "A153"
    1 "K358"
    2 "O441"
    2 "C509"
    1 "I219"
    2 "N309"
    1 "F311"
    1 "R572"
    2 "K358"
    end
    label values Sex Sex
    label def Sex 1 "Male", modify
    label def Sex 2 "Female", modify

    Here is a sample of the gender-inked codes (true = 700s codes for females and 120s codes for males):

    Female_ICD10_Codes Male_ICD10_Codes
    A34 B260
    B373 C600
    C510 C601
    C511 C602
    C512 C608
    C518 C609
    C519 C61
    C52 C620
    C530 C621
    C531 C629
    C538 C630
    C539 C631
    C540 C632
    C541 C637
    C542 C638
    C543 C639
    C548 D074
    C549 D075
    C55 D076
    C56 D176


    Thanks in advance!

  • #2
    As you define it, a misdiagnosis is a mismatch of "Diag1_code" and "Sex". A merge on these two variables will identify such mismatches.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str4(female_codes male_codes)
    "A34"  "B260"
    "B373" "C600"
    "C510" "C601"
    "C511" "C602"
    "C512" "C608"
    "C518" "C609"
    "C519" "C61"
    "C52"  "C620"
    "C530" "C621"
    "C531" "C629"
    "C538" "C630"
    "C539" "C631"
    "C540" "C632"
    "C541" "C637"
    "C542" "C638"
    "C543" "C639"
    "C548" "D074"
    "C549" "D075"
    "C55"  "D076"
    "C56"  "D176"
    end
    
    g id =_n
    reshape long @_codes, i(id) j(which) string
    *CREATE MISMATCH HERE
    gen Sex= cond(which=="female", 1, 2)
    rename _codes Diag1_code
    contract Diag1_code Sex, nomiss
    tempfile misdiagnosis
    save `misdiagnosis'
    
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte Sex str4 Diag1_code
    1 "B373"
    1 "R104"
    2 "K358"
    1 "J931"
    2 "O249"
    1 "I10"
    2 "N202"
    1 "I249"
    1 "K649"
    2 "C601"
    2 "O800"
    2 "I64"
    1 "C543"
    2 "J988"
    2 "B260"
    1 "N210"
    2 "J459"
    2 "C639"
    2 "O034"
    1 "C169"
    end
    label values Sex Sex
    label def Sex 1 "Male", modify
    label def Sex 2 "Female", modify
    merge m:1 Diag1_code Sex using `misdiagnosis', keep(master match)
    g wanted=_merge==3
    drop _*
    Res.:

    Code:
    . l, sep(0)
    
         +----------------------------+
         |    Sex   Diag1_~e   wanted |
         |----------------------------|
      1. | Female       B260        1 |
      2. |   Male       B373        1 |
      3. |   Male       C169        0 |
      4. |   Male       C543        1 |
      5. | Female       C601        1 |
      6. | Female       C639        1 |
      7. |   Male        I10        0 |
      8. |   Male       I249        0 |
      9. | Female        I64        0 |
     10. | Female       J459        0 |
     11. |   Male       J931        0 |
     12. | Female       J988        0 |
     13. | Female       K358        0 |
     14. |   Male       K649        0 |
     15. | Female       N202        0 |
     16. |   Male       N210        0 |
     17. | Female       O034        0 |
     18. | Female       O249        0 |
     19. | Female       O800        0 |
     20. |   Male       R104        0 |
         +----------------------------+
    
    .
    Last edited by Andrew Musau; 06 Oct 2022, 06:59.

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      As you define it, a misdiagnosis is a mismatch of "Diag1_code" and "Sex". A merge on these two variables will identify such mismatches.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str4(female_codes male_codes)
      "A34" "B260"
      "B373" "C600"
      "C510" "C601"
      "C511" "C602"
      "C512" "C608"
      "C518" "C609"
      "C519" "C61"
      "C52" "C620"
      "C530" "C621"
      "C531" "C629"
      "C538" "C630"
      "C539" "C631"
      "C540" "C632"
      "C541" "C637"
      "C542" "C638"
      "C543" "C639"
      "C548" "D074"
      "C549" "D075"
      "C55" "D076"
      "C56" "D176"
      end
      
      g id =_n
      reshape long @_codes, i(id) j(which) string
      *CREATE MISMATCH HERE
      gen Sex= cond(which=="female", 1, 2)
      rename _codes Diag1_code
      contract Diag1_code Sex, nomiss
      tempfile misdiagnosis
      save `misdiagnosis'
      
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte Sex str4 Diag1_code
      1 "B373"
      1 "R104"
      2 "K358"
      1 "J931"
      2 "O249"
      1 "I10"
      2 "N202"
      1 "I249"
      1 "K649"
      2 "C601"
      2 "O800"
      2 "I64"
      1 "C543"
      2 "J988"
      2 "B260"
      1 "N210"
      2 "J459"
      2 "C639"
      2 "O034"
      1 "C169"
      end
      label values Sex Sex
      label def Sex 1 "Male", modify
      label def Sex 2 "Female", modify
      merge m:1 Diag1_code Sex using `misdiagnosis', keep(master match)
      g wanted=_merge==3
      drop _*
      Res.:

      Code:
      . l, sep(0)
      
      +----------------------------+
      | Sex Diag1_~e wanted |
      |----------------------------|
      1. | Female B260 1 |
      2. | Male B373 1 |
      3. | Male C169 0 |
      4. | Male C543 1 |
      5. | Female C601 1 |
      6. | Female C639 1 |
      7. | Male I10 0 |
      8. | Male I249 0 |
      9. | Female I64 0 |
      10. | Female J459 0 |
      11. | Male J931 0 |
      12. | Female J988 0 |
      13. | Female K358 0 |
      14. | Male K649 0 |
      15. | Female N202 0 |
      16. | Male N210 0 |
      17. | Female O034 0 |
      18. | Female O249 0 |
      19. | Female O800 0 |
      20. | Male R104 0 |
      +----------------------------+
      
      .
      Thanks Andrew but it does not work and gave errors such as xij variables found, also wondering if there is another way because I don't think that it is practical to reshape and merge a huge data, the observations is nearly 200,000 ?!

      Comment


      • #4
        Just to explain it further, the male and female specific codes were not originally in the data. I have one variable that contain diagnosis codes in general for both females and males and I want to check if male specific code occur in any females obs, and vice versa, want to check if female specific code occur in any males obs? That is why I though to insert two new variables one include female codes and the second include males codes then do verification, but that does not work either!

        I appreciate any suggestions to solve this!

        Comment


        • #5
          To make it more clear, Diag1_code is a diagnosis ICD10 code for all OBS (females and males altogether), and there is a 127 codes specific to men diseases and 789 codes specific to females diseases (These are not built in the original data but I have them as a list). Sex value is 1== male and 2== female.

          What I want is something like this:

          Count or browse if Sex==1 & Diag1_code is one of the 789 females codes.

          Similarly:

          Count or brows if Sex==2 & Diag1_code is one of the 127 males codes ?

          Comment


          • #6
            I found the solution and just want to share it for those who may searching for same problem, use command levelsof then foreach.

            Comment

            Working...
            X