Announcement

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

  • code for 'if not'

    I need some help on how to generate a new variable with various conditions. The new variable is anyone who has been diagnosed with hcc at any visit other than 1 so the syntax below is what i wrote:

    generate probableHCConFUP=.
    replace probableHCConFUP=1 if hcc1==0 & hcc2==1| hcc3==1| hcc4==1| hcc5==1| hcc6==1| hcc7==1| hcc8==1| hcc9==1| hcc10==1

    The issue I am having is trying to get the 'probableHCConFUP=0' part; this should be the number of people without a diagnosis of hcc at any visit.

    I have tried replace probableHCConFUP=0 if hcc1==0 |hcc2==0| hcc3==0| hcc4==0| hcc5==0| hcc6==0| hcc7==0| hcc8==0| hcc9==0| hcc10==0 but this doesn't work. I have also tried doing it with each visit separately but i still don't get the right number.

    To note is the fact that someone may be diagnosed with hcc at one visit but not the other. the numbers after hcc denote the visit numbers.

    Kindly help as I'm not sure what I am missing.




  • #2
    Code:
    sysuse auto, clear
    
    su weight if foreign !=0

    Comment


    • #3
      If you want what you say in words, "people without a diagnosis of hcc at any visit", this should do it:

      Code:
       probableHCConFUP=  hcc1==1 | hcc2==1| hcc3==1| hcc4==1| hcc5==1| hcc6==1| hcc7==1| hcc8==1| hcc9==1| hcc10==1
      If you want something else (which looks like from your code because you are treating the first visit differently), you might want to try explaing again what you want and provide a toy datasample.

      Comment


      • #4
        Originally posted by Joro Kolev View Post
        If you want what you say in words, "people without a diagnosis of hcc at any visit", this should do it:

        Code:
        probableHCConFUP= hcc1==1 | hcc2==1| hcc3==1| hcc4==1| hcc5==1| hcc6==1| hcc7==1| hcc8==1| hcc9==1| hcc10==1
        If you want something else (which looks like from your code because you are treating the first visit differently), you might want to try explaing again what you want and provide a toy datasample.
        Let me clarify a bit:
        So this is a surveillance dataset. I am treating the first visit different because any cases diagnosed then are prevalent cases yet I am interested in the incident cases. So i would want anyone who has not been diagnosed with hcc at all at any of the visits.

        Comment


        • #5
          Code:
          generate probableHCConFUP = hcc1==0 & inlist(1, hcc2, hcc3, hcc4, hcc5, hcc6, hcc7, hcc8, hcc9, hcc10)

          Comment


          • #6
            Originally posted by Nick Cox View Post
            Code:
            generate probableHCConFUP = hcc1==0 & inlist(1, hcc2, hcc3, hcc4, hcc5, hcc6, hcc7, hcc8, hcc9, hcc10)
            thank you

            Comment

            Working...
            X