Announcement

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

  • How to drop all rows based on conditions on other rows

    Hi there, I would like know how to drop all id with HIVStatus==1 and visit==1
    I have tried "drop if HIVStatus==1 & visit==1" but it does not drop all rows of the same ID (i.e only rows that fit the conditions)
    In other words, I would like to drop all id listed in "list id if HIVStatus==1 & visit==1"

    Here is the example data
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long Id float(HIVStatus visit)
    48 0 1
    48 0 2
    48 0 3
    217 0 1
    217 0 2
    217 0 3
    261 . 1
    265 . 1
    271 0 1
    271 0 2
    271 0 3
    403 . 1
    411 . 1
    411 . 2
    500 0 1
    500 . 3
    537 . 1
    537 . 3
    564 0 1
    614 0 1
    614 0 3
    633 1 1
    633 1 3
    708 0 1
    708 0 2
    end
    label values visit visit
    label def visit 1 "Baseline", modify
    label def visit 2 "2018 Follow-up", modify
    label def visit 3 "2019 Follow-up", modify
    [/CODE]

    This is my first STATALIST post and I am new to STATA so feel free to give your comments!
    Also apologies for the possibly ambiguous title, I could not think of other ways to describe it.

  • #2
    here is one solution of many possible:
    Code:
    gen byte td1=HIVStatus==1 & visit==1
    egen byte td2=max(td1), by(Id)
    drop if td2
    and then you will probably want to drop td1 and td2

    Comment


    • #3
      For more on Rich's technique, see https://www.stata.com/support/faqs/d...ble-recording/

      The correspondence

      any : max

      all : min

      should be part of any toolbox here.

      Comment

      Working...
      X