Announcement

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

  • Filtering by certain criteria

    I'm having an issue with coding.

    So far I have:

    gen baselinescore = ( Q1+ Q2+ Q3+ Q4+ Q5+ Q6+ Q7+ Q8+ Q9)

    I need to keep only those records where Q1+Q2 >=3. I've tried drop and a few other things but haven't figured it out yet.

    Thanks.

  • #2
    Try this:
    Code:
    gen keep=1 if Q1+Q2>=3
    keep if keep==1

    Comment


    • #3
      Thank you!

      Comment


      • #4
        Even simpler is just:

        Code:
        keep if Q1 + Q2 >= 3
        (Note: This code, as well as the code in #2, will also retain observations where Q1 or Q2 has a missing value, because then Q1+Q2 will itself be missing, and missing value is interpreted as larger than every number. If you don't want to retain those observations, add -& !missing(Q1, Q2)- to the end of that line of code.)

        Comment

        Working...
        X