Announcement

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

  • Newvar based on multiple conditions

    Hello,

    I know others have posted on this but I am still having some difficulty, although it seems like it would be easier than I am making it. I am trying to create a new variable that is = 1 if var1-var8 are <=35.

    Thanks

  • #2
    Welcome to Statalist.

    If you mean that var1<=35 and var2<=35 and ... and var8<35 then
    Code:
    egen vmax = rowmax(var1-var8)
    generate x = vmax<=35
    will create x=1 if all 8 values are no greater than 35, x=0 otherwise, noting that any missing values in var1 ... var8 are ignored in the calculation of the maximum.

    Comment


    • #3
      Thank you for the response. And I apologize I was not clear enough. I mean that each var must be <=35. So newvar would be 1 if var1 <=35 AND var2<=35...AND var8<=35.

      Thanks for the welcome. My first post.

      Comment


      • #4
        That is what William's solution does. For all of the variables to be no greater than 35, it suffices that their maximum is no greater than 35.

        Comment


        • #5
          Thank you! Worked great.

          Comment

          Working...
          X