Announcement

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

  • Identifying ICD-codes in 30 different variables

    Hi,

    I have a dataset containing one variable identifying study participants and 30 variables containing ICD-codes (one per variable, strings). I need to identify every code indicating diabetes and generate a new variable, coded as 1 or 0 to indicate the presence or absence of diabetes. Of course I can write gen diabetes==1 if var1=="xxx" etc and repeat this up to var30. Alas there are quite a lot of different ICD-codes for diabetes so it would take a lot of time. Does anyone know of a faster way?

    Best wishes,

    David

  • #2
    Please see https://www.statalist.org/forums/for...79321-for-loop, #2. Thanks.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Cross-reference should be to https://www.statalist.org/forums/for...79321-for-loop Please use the CONTACT US button (bottom right) to contact the forum administrators to re-register with your full name.


      The following can be extended:


      Code:
      gen diabetes = 0 
      
      forval j = 1/30 { 
           replace diabetes = 1 if var`j' == "xxx" 
      }
      See also documentation on the inlist() function

      Comment


      • #4
        If you are working with ICD codes, Stata's commands that are designed specifically for working with ICD9 and ICD10 codes may help you. If you are not familiar with them,
        Code:
        help icd
        is a place to start.

        Comment


        • #5
          Thank you so much! I´ll request the name change. Best wishes,
          David

          Comment

          Working...
          X