Announcement

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

  • Egen minimum number of variables in list with given value

    I need to create a binary depression variable that would indicate whether or not at least 5 out 8 symptom variables have a value above 2.
    Is there a faster way to do this than generating 8 binary symptom variables, adding them, and finally creating the binary depression variable if the total is above 5?

    Thank you,
    Emma

  • #2
    Tell us more about your data. If the 8 binary variables do not yet exist, tell us what does.

    Comment


    • #3
      The 8 symptom variables have a range 0-3 (Likert scale for frequency experiencing the symptom, from never to everyday). People are considered depressed if they report a value of 2 and above on items 1 or 2, and at least 5 out of 8 symptoms with values 2 and above. I tend to write everything out and realize that I could probably be using shortcuts, but I cannot find any egen function that contain "if 5 out of 8 is true".

      Comment


      • #4

        Code:
        gen wanted = 0 
        
        quietly foreach v of var symptom* { 
            replace wanted = wanted + inlist(`v', 2, 3) if `v' < . 
        } 
        
        replace wanted = wanted >= 5
        See also http://www.stata-journal.com/sjpdf.h...iclenum=pr0046

        Comment


        • #5
          Thank you!

          Comment

          Working...
          X