Announcement

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

  • Multiple groups from two variables

    Hello,

    I am trying to create a newvar that has 0 and 1 from two variables.

    The first variable (var1) is binary (yes = 1, no = 0). The second variable (var2) is a range of values (-2 through +2 at 0.5 intervals; ie. -2, -1.5, -0.5, 0, etc).

    For the newvar:

    1. I want 0 to be true if var1 = 0 and var2 to be >= -0.5.
    2. I want 1 to be true if var1 = 1 and var2 to be >= -0.5.

    Notice, this will also be working with missing data. Missing data will be any rows with var2 <= -1, which I don't want included in my future analysis.

    Appreciate the help!
    Thanks

  • #2
    I believe this code should work:

    Code:
    gen newvar = 0 if var1 == 0 & var2 >= -0.5
    replace newvar = 1 if var1 == 1 & var2 >= -0.5

    Comment


    • #3
      Yup, worked! Thank you.

      Comment

      Working...
      X