Announcement

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

  • icd9 and icd10 codes

    Dear all

    I a am trying to create a mental condition variable "organic" using data from both icd10 and icd9 codes. The icd10 codes seem to work well if I run the syntax without icd9 codes, but am having trouble with icd9 codes. I have looked at previous posts related to this, and tried the "icd clean TDIAG1, gen (xxx)" to create a copy of each of the TDIAG* variables and this failed. I would like the new variable "organic" to be based on icd10 and icd9 codes as described in the below syntax:

    ERROR MESSAGE:
    TDIAG1 contains invalid ICD-9 codes

    SYNTAX:
    foreach v of varlist TDIAG* {
    icd10 generate organic10_`v' = `v', range(F00* F01* F02* F03* F04* F05* F06* F07* F08* F09*)
    icd9 generate organic9_`v' = `v', range(290* 293* 294*)
    }
    egen organic = rowmax(organic9_TDIAG* organic10_TDIAG*)



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 (TDIAG1 TDIAG2 TDIAG3 TDIAG4 TDIAG5 TDIAG6 TDIAG7 TDIAG8 TDIAG9)
    "F500"  "F3220" "Z915"  "Z638"  ""      ""      ""     ""      ""    
    "O81"   "O688"  "O631"  "O721"  "O700"  "O864"  "O16"  "O7182" "Z658"
    "F410"  "Z590"  ""      ""      ""      ""      ""     ""      ""    
    "Q833"  ""      ""      ""      ""      ""      ""     ""      ""    
    "Q048"  "G4011" "L299"  "Y450"  "Y9222" "R11"   "I959" ""      ""    
    "F120"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K353"  ""      ""      ""      ""      ""      ""     ""      ""    
    "R104"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K358"  ""      ""      ""      ""      ""      ""     ""      ""    
    "R633"  "K219"  ""      ""      ""      ""      ""     ""      ""    
    "S199"  "S299"  "W109"  "Y929"  "U739"  "Z638"  "F919" ""      ""    
    "K759"  "Z290"  ""      ""      ""      ""      ""     ""      ""    
    "S959"  "X59"   "Y9230" "U5009" ""      ""      ""     ""      ""    
    "K590"  "K564"  "R14"   "Z934"  ""      ""      ""     ""      ""    
    "E1064" ""      ""      ""      ""      ""      ""     ""      ""    
    "J353"  "T16"   "W44"   "Y929"  "U739"  "H659"  ""     ""      ""    
    "R104"  "J069"  ""      ""      ""      ""      ""     ""      ""    
    "F919"  ""      ""      ""      ""      ""      ""     ""      ""    
    "H653"  ""      ""      ""      ""      ""      ""     ""      ""    
    "S199"  "W51"   "Y9231" "U5709" ""      ""      ""     ""      ""    
    "K37"   ""      ""      ""      ""      ""      ""     ""      ""    
    "R103"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K37"   "Z753"  ""      ""      ""      ""      ""     ""      ""    
    "N12"   ""      ""      ""      ""      ""      ""     ""      ""    
    "S526"  "W188"  "Y9230" "U501"  ""      ""      ""     ""      ""    
    "J459"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K029"  "K036"  "K049"  ""      ""      ""      ""     ""      ""    
    "S0085" "S500"  "Y0402" "Y9209" "U739"  ""      ""     ""      ""    
    "F100"  ""      ""      ""      ""      ""      ""     ""      ""    
    "T424"  "T519"  "Y15"   "Y11"   "Y929"  "U739"  ""     ""      ""    
    "S064"  "S021"  "S0602" "V4818" "Y929"  "U739"  "R455" "H532"  "Z720"
    "M6743" ""      ""      ""      ""      ""      ""     ""      ""    
    "B349"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K011"  ""      ""      ""      ""      ""      ""     ""      ""    
    "S6261" "X59"   "Y929"  "U72"   ""      ""      ""     ""      ""    
    "R468"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F500"  "Z915"  ""      ""      ""      ""      ""     ""      ""    
    "F500"  "R680"  "R000"  "E162"  "F419"  "S5188" "W49"  "Y9222" "U739"
    "F100"  ""      ""      ""      ""      ""      ""     ""      ""    
    "T407"  "R073"  "R000"  "X42"   "T598"  "X479"  "T510" "X45"   "Y929"
    "F6031" "Z631"  ""      ""      ""      ""      ""     ""      ""    
    "K37"   ""      ""      ""      ""      ""      ""     ""      ""    
    "N832"  ""      ""      ""      ""      ""      ""     ""      ""    
    "R4581" "Z592"  ""      ""      ""      ""      ""     ""      ""    
    "S099"  "W22"   "Y929"  "U739"  ""      ""      ""     ""      ""    
    "F913"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F432"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F100"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F432"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F3220" "R4581" "K590"  "Z933"  ""      ""      ""     ""      ""    
    "J050"  "E876"  ""      ""      ""      ""      ""     ""      ""    
    "F919"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K010"  "K011"  ""      ""      ""      ""      ""     ""      ""    
    "O82"   "O629"  "O688"  "O624"  "Z370"  "Z223"  "Z292" ""      ""    
    "F3220" ""      ""      ""      ""      ""      ""     ""      ""    
    "R4581" "Z631"  ""      ""      ""      ""      ""     ""      ""    
    "K004"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F500"  "S519"  "X788"  "S1090" "X83"   "Y9222" "U738" ""      ""    
    "R630"  "E86"   ""      ""      ""      ""      ""     ""      ""    
    "J039"  ""      ""      ""      ""      ""      ""     ""      ""    
    "Z638"  "R073"  ""      ""      ""      ""      ""     ""      ""    
    "S0265" "S0266" "Y0404" "Y9221" "U739"  ""      ""     ""      ""    
    "F101"  "F111"  "F121"  "R456"  "F410"  "H518"  "Y494" "Y9222" "Z720"
    "K029"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F3290" ""      ""      ""      ""      ""      ""     ""      ""    
    "R4589" "R465"  "R51"   ""      ""      ""      ""     ""      ""    
    "F431"  "F819"  "Z616"  "Z631"  ""      ""      ""     ""      ""    
    "F341"  "R4581" "F913"  "F430"  "Z731"  "Z639"  "Z631" "Z915"  ""    
    "Z038"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K358"  "K380"  ""      ""      ""      ""      ""     ""      ""    
    "J350"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K4090" ""      ""      ""      ""      ""      ""     ""      ""    
    "S6232" "W22"   "Y929"  "U739"  "Z720"  ""      ""     ""      ""    
    "F602"  ""      ""      ""      ""      ""      ""     ""      ""    
    "S9081" "S198"  "R101"  "V4709" "Y9249" "U72"   ""     ""      ""    
    "S199"  "V4769" "Y9248" "U739"  ""      ""      ""     ""      ""    
    "M205"  ""      ""      ""      ""      ""      ""     ""      ""    
    "R630"  "Z915"  ""      ""      ""      ""      ""     ""      ""    
    "S5311" "W094"  "Y9288" "U72"   ""      ""      ""     ""      ""    
    "T391"  "X60"   "Y929"  "U738"  "F430"  "Z614"  ""     ""      ""    
    "R103"  ""      ""      ""      ""      ""      ""     ""      ""    
    "H020"  ""      ""      ""      ""      ""      ""     ""      ""    
    "E201"  ""      ""      ""      ""      ""      ""     ""      ""    
    "S5250" "V8000" "Y929"  "U635"  ""      ""      ""     ""      ""    
    "S8281" "W22"   "Y9209" "U739"  ""      ""      ""     ""      ""    
    "R104"  ""      ""      ""      ""      ""      ""     ""      ""    
    "K8050" ""      ""      ""      ""      ""      ""     ""      ""    
    "T407"  "X42"   "Y9209" "U739"  ""      ""      ""     ""      ""    
    "S0152" "Y34"   "X58"   "Y9218" "U739"  "K121"  "F840" ""      ""    
    "S0151" "Y0409" "Y929"  "U739"  "F100"  "Y908"  ""     ""      ""    
    "R13"   "K220"  ""      ""      ""      ""      ""     ""      ""    
    "K029"  ""      ""      ""      ""      ""      ""     ""      ""    
    "T509"  "X64"   "Y929"  "U738"  ""      ""      ""     ""      ""    
    "F3290" ""      ""      ""      ""      ""      ""     ""      ""    
    "G248"  ""      ""      ""      ""      ""      ""     ""      ""    
    "F418"  "F913"  ""      ""      ""      ""      ""     ""      ""    
    "E109"  ""      ""      ""      ""      ""      ""     ""      ""    
    "S050"  "S058"  "Y0402" "Y9209" "U739"  ""      ""     ""      ""    
    "S6230" "S6261" "W026"  "Y929"  "U739"  ""      ""     ""      ""    
    "K590"  "K592"  "Z911"  "F3290" "Z934"  "Z924"  ""     ""      ""    
    end




  • #2
    The problem here is obvious. You don't have any ICD9 codes, and therefore the -icd9- command complains. If you did have them, then they aren't shown in your data example. Further more, it would not be wise to mix ICD versions within the same varaibles so that you can execute different ICD-related commands according to the version of those codes in each variable.

    Comment


    • #3
      This is a sample of the data, which has more than 30,000 records. I do have ICD-9 codes

      Comment


      • #4
        is it possible for the icd9 and icd10 codes to appear in the same observation? if no, do you have something that will identify for the observation whether it has icd9 or icd10 (e.g., a date even if limited to quarter and year)? then you can use Stata's icd9 and icd10 commands with an "if" condtion

        if it is possible to have icd9 and icd10 codes in the same observation you may need something more complicated, including a -reshape- long and then, after using Stata's commands, a -reshape- back to wide (maybe)

        Comment


        • #5
          Thanks for the advice. I have created copies of variables containing icd9 codes only, and used dates to identify icd9 and icd10 codes.
          I am still getting the same problem with the message "....contains invalid icd-9 codes"

          Is there a way of getting round this without using the "icd9 generate" command and simply "generate"

          Comment


          • #6
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str6 (TDIAG1 TDIAG2 TDIAG3 TDIAG4 TDIAG5 TDIAG6 TDIAG7 TDIAG8 TDIAG9)
            "F500"  "F3220" "2955"  "Z638"  ""      ""      ""     ""      ""    
            "O81"   "O688"  "O631"  "O721"  "2935"  "O864"  "O16"  "O7182" "Z658"
            Q833"  ""      ""      "2200"      ""      ""      ""     ""      ""    
            "Q048"  "G4011" "L299"  "Y450"  "" "R11"   "2900" ""      ""   
            end
            
            gen wanted=0
            foreach var of varlist TDIAG*{
                qui replace wanted= regexm(trim(`var'), "(^290|^293|^294)") if !wanted
            }
            Res.:

            Code:
            . l
            
                 +-----------------------------------------------------------------------------------------+
                 | TDIAG1   TDIAG2   TDIAG3   TDIAG4   TDIAG5   TDIAG6   TDIAG7   TDIAG8   TDIAG9   wanted |
                 |-----------------------------------------------------------------------------------------|
              1. |   F500    F3220     2955     Z638                                                     0 |
              2. |    O81     O688     O631     O721     2935     O864      O16    O7182     Z658        1 |
              3. |   Q833                                2200                                            0 |
              4. |   Q048    G4011     L299     Y450               R11     2900                          1 |
                 +-----------------------------------------------------------------------------------------+

            Comment


            • #7
              Thanks very much this works.

              Comment

              Working...
              X