Announcement

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

  • using foreach command with icd10 command

    Hi,

    I am working with HCUP NIS dataset. I am trying to create an indicator for depression using icd10 diagnosis codes. There are 30 diagnoses variables; I10DX1-I10DX30.
    Depression codes are F32, F320, F321, F322, F323, ...F33, F330, F333, etc.
    I'd like to capture these codes from DX2 to DX30 as secondary diagnosis.

    gen depression=0

    . foreach var of I10_DX2-I10_DX30 {
    2. icd10 replace depression=1,range(F32*)
    3. }
    Why this is an invalid syntax?

    Thanks,

    Maryam

  • #2
    as far as I can see, there is no such command as -icd10 replace-; also, your -foreach line is incorrect; how about the following instead (untested as there is no sample data here):
    Code:
    gen byte depression=0
    foreach var of varlist I10_DX2-I10_DX30 {
    replace depression=1 if substr(`var',1,3)=="F32"
    }

    Comment


    • #3
      Rich Goldstein Thank you so much. It worked! You are correct there is no replace option for icd10. Thanks again.

      Comment


      • #4
        How can I replace "F32" with "0HTU0ZZ 0KTH0ZZ 0KTJ0ZZ 07T50ZZ 07T60ZZ 07T70ZZ 07T70ZZ 07T80ZZ 07T90ZZ 0HTT0ZZ 0HTU0ZZ 0KTH0ZZ 0KTJ0ZZ etc."
        Originally posted by Rich Goldstein View Post
        as far as I can see, there is no such command as -icd10 replace-; also, your -foreach line is incorrect; how about the following instead (untested as there is no sample data here):
        Code:
        gen byte depression=0
        foreach var of varlist I10_DX2-I10_DX30 {
        replace depression=1 if substr(`var',1,3)=="F32"
        }

        Comment

        Working...
        X