Announcement

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

  • Expression too long

    Hi everyone- I am a new user here.

    I am running into a problem.

    STATA does not allow to use more than 10 arguments for strings- and says expression too long. However, I have more than 10.

    For example- there are multiple ICD9 codes for myocarditis, and to get all the patients with myocarditis, I would need to get all those ICD codes. a nd then I place them as binary values 1=present and 0=absence of this diagnosis.

    If I make two variables like myocarditis1 and myocarditis 2 with less than 10 arguments each so that STATA wont give error message, it will make a new column for each variable : myocarditis1 with 0 and 1, and similarly a new column with 0 and 1 for myocarditis 2. How can I combine those two variable columns to get a single column? The code I use to generate myocarditis variable is . 1/25 is because there are 25 columns for the codes for diagnosis from DX1 to DX25.

    gen myocarditis1=0
    forvalues j=1/25{
    replace myocarditis1=1 if inlist(DX`j', "4290", "42299", "42290", "07423","07420", "03640", "03643", "4220" )
    }
    label variable myocarditis1 "myocarditis2"


    And for myocarditis 2

    gen myocarditis2=0
    forvalues j=1/25{
    replace myocarditis2=1 if inlist(DX`j', "I514", "I408", "I409", "B3320", "A3950", "A3952", "I401", "I400", "A381", "J1082", "I41" )
    }
    label variable myocarditis2 "myocarditis2"


    Thank you.
    Laxmi

  • #2
    Sorry for the error in the first code chunk. Should be following- "myocarditis1" in the quotes.

    gen myocarditis1=0
    forvalues j=1/25{
    replace myocarditis1=1 if inlist(DX`j', "4290", "42299", "42290", "07423","07420", "03640", "03643", "4220" )
    }
    label variable myocarditis1 "myocarditis1"

    Comment


    • #3
      Welcome to Statalist.

      Your example code can be simplified to
      Code:
      gen myocarditis1=0
      forvalues j=1/25{
          replace myocarditis1=1 if inlist(DX`j', "I514", "I408", "I409", "B3320", "A3950", "A3952", "I401", "I400", "A381", "J1082", "I41" )
          replace myocarditis1=1 if inlist(DX`j', "4290", "42299", "42290", "07423","07420", "03640", "03643", "4220" )
      }
      label variable myocarditis1 "myocarditis1"
      But if you have not done so, check Stata's ICD9 command to see if it can help you (read the output of help icd9).

      Comment


      • #4
        Thank you William. It worked- how nice! You saved me quite a bit of time. I should have asked the question here earlier!!

        Comment


        • #5
          For long lists, another approach is to feed the allowed codes into a different dataset and merge. https://www.stata.com/support/faqs/d...ets/index.html has been an FAQ since 2001.

          Comment

          Working...
          X