Announcement

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

  • Drop or Keep command?

    I have data in long format. How do I drop subjects (id) who have only observations(days) >300. I want to keep subjects that have observations(days) <300 days & >=300 days, but want to drop subjects that only have observations >300 days and have no observations smaller than 300 days. For example (see below), I want to keep subject with id 1 and want to drop subject with id 2. But I need a code for the whole dataset of course, not just for these two subjects. Please help.

    id days
    1 100
    1 300
    1 500
    2 1000

  • #2
    See https://www.stata.com/support/faqs/d...ble-recording/.

    Code:
    bys id: egen tag= min(days>300)
    drop if tag
    Last edited by Andrew Musau; 23 Dec 2025, 11:29.

    Comment


    • #3
      Thank you very much Andrew Musau for your fast response! It worked!

      Comment

      Working...
      X