Announcement

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

  • Mapping ICD10 into ICD11 by looping

    Hi,

    Since ICD11 is effective in using by most countries now, I wonder if there it will be included (built in) in next updates?

    I think what I need should be achieved with easy command, but I couldn't figure it out.

    I tried the following:

    levelsof icd10, local(Names)
    gen newICD = 0
    foreach n of local Names {
    replace newICD = icd11 if ( icd10 == "`n'")
    }
    type mismatch
    r(109);


    What I need is to create a new string variable equal the value of icd11 for each corresponding icd10 value (in the example below, each icd10 with the corresponding icd11 new value). Here is an example of data:


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str7 icd10 str28 icd11
    "A00"  "1A00"              
    "A000" "1A00&XN8P1"        
    "A001" "1A00&XN62R"        
    "A009" "1A00"              
    "A01"  "1A0Z&XN0QE"        
    "A010" "1A07Z"             
    "A011" "1A08"              
    "A012" "1A08"              
    "A013" "1A08"              
    "A014" "1A08"              
    "A02"  "1A09Z"             
    "A020" "1A090"             
    "A021" "1C41&XN0QE"        
    "A022" "1A09Z"             
    "A028" "1A09Z"             
    "A029" "1C41"              
    "A03"  "1A02"              
    "A030" "1A02"              
    "A031" "1A02"              
    "A032" "1A02"              
    "A033" "1A02"              
    "A038" "1C41"              
    "A039" "1A02"              
    "A04"  "1A0Z"              
    "A040" "1A030"             
    "A041" "1A031"             
    "A042" "1A032"             
    "A043" "1A033"             
    "A044" "1A03Z"             
    "A045" "1A06"              
    "A046" "1A05"              
    "A047" "1A04"              
    "A048" "1A0Z"              
    "A049" "1A0Z"              
    "A05"  "1A1Z"              
    "A050" "1A10"              
    "A051" "1A11Z"             
    "A052" "1A12"              
    "A053" "1A1Z"              
    "A054" "1A13"              
    "A058" "1A1Z"              
    "A059" "1A1Z"              
    "A06"  "1A36Z"             
    "A060" "1A3600"            
    "A061" "1A360Z"            
    "A062" "1A360Z"            
    "A063" "1A3601"            
    "A064" "1A3610"            
    "A065" "1A3611"            
    "A066" "1A361&XA9738/1D033"
    end

    Thanks!

  • #2
    Your question is not well-posed. You have 2 variables, "icd10" and "icd11". Isn't the value of icd11 indicative of the corresponding icd10 code? If so, what new variable do you want to generate?


    levelsof icd10, local(Names)
    gen newICD = 0
    foreach n of local Names {
    replace newICD = icd11 if ( icd10 == "`n'")
    }
    The type mismatch error results from you defining a numerical variable

    gen newICD = 0
    and then trying to replace its values with those from a string variable

    replace newICD = icd11 if ( icd10 == "`n'")
    [.] Maybe create a third variable illustrating how you want the result to look like.

    Comment


    • #3
      Thank you for your time and response. let me illustrate:

      suppose we have var1 with ICD10 codes and var2 the updated ICD11 codes, I want to create a new variable to transform (replace) each icd10 code with its corresponding icd11 codes. For instance, whenever found cod "A010" transform it into "1A07Z", and whenever there is "A011" transform it into "1A08" and whenever there is "A020" transform it to "1A090 " etc. so basically it like attaching a new code for the previous one and ask state whenever found it transform it to the new one. Hope this clarify it.
      var1 var2 var3
      "A010" "1A07Z" "1A07Z"
      "A011" "1A08" "1A08"
      "A012" "1A08" "1A08"
      "A013" "1A08" "1A08"
      "A014" "1A08" "1A08"
      "A02" "1A09Z" "1A09Z"
      "A020" "1A090" "1A090"
      Thanks in advance

      Comment


      • #4
        As I stated in #2, you are just generating the same variable (var2= var3).

        Code:
        gen var3=var2

        Comment


        • #5
          That would be easy! maybe I did not explain it well. Let me try again.



          In the original data, there is diagnosis code (which is based on ICD10) representing by var (diag), then I copied icd10who and icd11who from WHO website for mapping icd10 into icd11 next to each other. What I want is as follow:
          If Stata found the code "A00" in the (diag) to transform it in under new variable (lets call it newicd) to "1A00" and if find code "I460" in (diag) to transform it to "MC82Z" under newicd etc.

          ​​​​​​​
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str4 diag double age str7 icd10who str28 icd11who
          "R99"                   100 "A00"  "1A00"              
          "A419"                    0 "A000" "1A00&XN8P1"        
          "C809"                    0 "A001" "1A00&XN62R"        
          "I469"                    0 "A009" "1A00"              
          "I469"                    0 "A01"  "1A0Z&XN0QE"        
          "I469"                    0 "A010" "1A07Z"             
          "I469"                    0 "A011" "1A08"              
          "I509"                    0 "A012" "1A08"              
          "P073"                    0 "A013" "1A08"              
          "P073"                    0 "A014" "1A08"              
          "P073"                    0 "A02"  "1A09Z"             
          "P073"                    0 "A020" "1A090"             
          "P071"                    0 "A021" "1C41&XN0QE"        
          "P070"                    0 "A022" "1A09Z"             
          "P070"                    0 "A028" "1A09Z"             
          "P073"                    0 "A029" "1C41"              
          "P073"                    0 "A03"  "1A02"              
          "P073"                    0 "A030" "1A02"              
          "P072"                    0 "A031" "1A02"              
          "P072"                    0 "A032" "1A02"              
          "P073" .0027397260273972603 "A033" "1A02"              
          "P073" .0027397260273972603 "A038" "1C41"              
          "P070" .0027397260273972603 "A039" "1A02"              
          "P073" .0027397260273972603 "A04"  "1A0Z"              
          "P219"                    0 "A040" "1A030"             
          "P229"                    0 "A041" "1A031"             
          "P220"                    0 "A042" "1A032"             
          "P229"                    0 "A043" "1A033"             
          "P220"                    0 "A044" "1A03Z"             
          "P220"                    0 "A045" "1A06"              
          "P220"                    0 "A046" "1A05"              
          "P220"                    0 "A047" "1A04"              
          "P220"                    0 "A048" "1A0Z"              
          "P220"                    0 "A049" "1A0Z"              
          "P220"                    0 "A05"  "1A1Z"              
          "P220"                    0 "A050" "1A10"              
          "P220" .0027397260273972603 "A051" "1A11Z"             
          "P220" .0027397260273972603 "A052" "1A12"              
          "P239" .0027397260273972603 "A053" "1A1Z"              
          "P239" .0027397260273972603 "A054" "1A13"              
          "P269" .0027397260273972603 "A058" "1A1Z"              
          "P280"                    0 "A059" "1A1Z"              
          "P280"                    0 "A06"  "1A36Z"             
          "P280"                    0 "A060" "1A3600"            
          "P280"                    0 "A061" "1A360Z"            
          "P280"                    0 "A062" "1A360Z"            
          "P280"                    0 "A063" "1A3601"            
          "P280"                    0 "A064" "1A3610"            
          "P280"                    0 "A065" "1A3611"            
          "P280" .0027397260273972603 "A066" "1A361&XA9738/1D033"
          end

          Comment


          • #6
            I know nothing about ICD 11 but unless the move from 10 to 11 is MUCH easier than the move from 9 to 10, this will not be easy; you might want to see: Ellis, RP, et al. (2020), "Diagnostic category prevalence in 3 classification systems across the transition to the International Classification of Diseases, Tenth Revision, Clinical Modification, JAMA Network Open, 3(4), e202280. doi: 10.1001/jamanetworkopen.2020.2280

            Comment


            • #7
              To solve such issue, I would use Excel to create replace command for more than 12000 times as an example below:

              gen newicd="."

              replace newicd = " 1D4A " if diag == " A981 "
              replace newicd = " 1D4B " if diag == " A982 "
              replace newicd = " 1D601Z " if diag == " A983 "
              replace newicd = " 1D6001 " if diag == " A984 "
              replace newicd = " 1D620 " if diag == " A985 "
              replace newicd = " 1D6Z " if diag == " A988 "
              replace newicd = " 1D4Z " if diag == " A99 "

              I was hoping if someone has better solution in more efficient way!

              Comment


              • #8
                First, let me endorse Rich Goldstein 's remark that this kind of simple translation from ICD10 to ICD11 is probably too simple to be realistic.

                Be that as it may, you have only made your life complicated by adjoining the ICD10 to ICD11 crosswalk into your original data set. It would have been simpler had you kept them separate.

                Nevertheless, the damage is easily reversed. Once they are separated (here I do it with frames instead of data sets), it is just a question of linking the diag variable with the icd10who variable in the other frame and then bringing in the corresponding icd11 variable. The code looks like this:
                Code:
                frame put *who, into(crosswalk)
                drop *who
                
                frame crosswalk: isid icd10who, sort
                
                frlink m:1 diag, frame(crosswalk icd10who)
                frget icd11who, from(crosswalk)
                Now, I have not been able to really test this code in your example data because all of the diag codes are from late in the alphabet, whereas all of the icd10who codes are from early in the alphabet, so there are no matches. But this code is simple enough that I'm confident that in a real data set that shows the complete icd10 to icd11 crosswalk, it will perform correctly.

                If you are done with the crosswalk at that point you can -drop crosswalk- and -frame drop crosswalk-.

                Added: Crossed with #7. I think you will find the solution here is preferable.
                Last edited by Clyde Schechter; 15 Feb 2023, 12:55.

                Comment


                • #9
                  Nice to hear from you @Clyde Schechter . As usual your code works and helpful. I appreciate that

                  One more question please, if kept them separate (by not adjoining the ICD10 next to ICD11) what would the code be in this case?


                  Many thanks

                  Comment


                  • #10
                    One more question please, if kept them separate (by not adjoining the ICD10 next to ICD11) what would the code be in this case?
                    I'm not sure what to make of this question. I think it perhaps misunderstands my comment about having adjoined ICD10 and ICD11 into the data set containing the diag variable. The issue is not having ICD10 and ICD11 together: they must be in the same data somewhere in order to convert between them. What I was saying is that it was not helpful to have those two variables in the same data set as your diag variable. And if you follow the code I proposed carefully, you will se that what it does is remove ICD10 and ICD11 (together) into a separate frame, and then the frames link diag to ICD10 across the frames.

                    Had you had two separate data sets, dataset1 containing diag, and dataset2 containing icd10who and icd11who, I would have proposed
                    Code:
                    use dataset1, clear
                    clonevar icd10who = diag
                    merge m:1 icd10who using dataset2, keepusing(icd11who) keep(match master)

                    Comment


                    • #11
                      Yes, I noticed that. Very grateful, Clyde. This is brilliant and I will read more about it.

                      Many thanks

                      Comment

                      Working...
                      X