Announcement

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

  • Failed to gen missing values

    Hi,

    I'm counting how many missing values(.) a variable has, and my previous code only counted 0 and 1 variables, making the 0 and missing values combined.
    I'm now trying to separate the missing values from the 0 but I've failed many many times, the number of 1 is not matched with the previous one, can someone please guide me how to count 1, 0, missing value(.) separately?

    gen O1 = 0
    replace O1 = 1 if under == 0 & inlist(c314, 1, 2) & (inlist(c300, 1, 2, 3, 4) | c304 == 1 | inlist(c3, 3, 4, 5) | inlist(c340, 3, 4, 5, 6) | inlist(c350, 3, 4, 5, 6) | inlist(c321, 1, 2) | inlist(c3, 1, 2) | c323 == 2)

    gen O2 = 0
    replace O2 = 1 if (inlist(c340, 2, 3) | inlist(c350, 2, 3)) & (inlist(c360, 2, 3) | inlist(c370, 1, 2) | inlist(c371, 1, 2) | inlist(c372, 1, 2) | inlist(c373, 1, 2) | inlist(c374, 1, 2) | inlist(c375, 1, 2))


    gen O3 = 0
    replace O3 = 1 if c340 == 1 & c350 == 1 & inlist(c360, 2, 3) & (inlist(c370, 1, 2) + inlist(c371, 1, 2) + inlist(c372, 1, 2) + inlist(c373, 1, 2) + inlist(c374, 1, 2) + inlist(c375, 1, 2)) >= 3

    gen OS = 0
    replace OS = 1 if (O1 == 1 | O2 == 1 | O3 == 1) & A14 == 0 & B14 == 0 & D14 == 0

  • #2
    Hello and welcome to Statalist.

    This is very hard to tackle because the goal isn't very clear (you wanted to count a missing that a variable has, but the codes hinted that you're counting across a case), and the codes are codes that didn't work, which makes diagnosis a lot more difficult.

    Could you perhaps try another approach asking this question? Show us some same data using dataex, and tell us what you'd like to achieve. You don't have to show all the cXXX variables, just about 3 to 5 will be fine.

    Comment


    • #3
      Nothing in your code mentjons missing values. I see checks for values being variously 0, 1, 2, 3, 4, 5 or 6 and none of those is missing unless that's your private code.

      Comment


      • #4
        Thank you very much Ken Chui and Nick Cox, sorry for the late reply as I tried to fix it myself. Now that I've figured it out, my code didn't give a definition for the missing value, thank you again😊

        Comment

        Working...
        X