Announcement

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

  • Removing observations with more than one first visit

    I have data from a clinic. Patients can have a first episode and an unrelated episode visit. However, some patients have more than one first-episode visit. I need to remove any subsequent first-episode visits. I will keep the unrelated episode visits. Is there a way to program this? Your help will be appreciated.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id visits date)
      6 0 21954
      7 0 21637
     12 0 21486
     12 0 21319
     12 0 22448
     14 0 22513
     26 0 22123
     38 0 21479
     38 0 21896
     38 0 21413
     58 0 21873
     58 0 22397
     58 0 22131
     76 0 21885
     76 0 22279
     76 0 21302
     76 0 22033
     80 0 22487
     83 0 22610
     83 1 22611
     85 0 22275
     85 1 22297
     95 0 21424
     95 0 22550
     99 0 22221
    120 0 21550
    120 0 21871
    120 0 21548
    217 0 21957
    217 0 22335
    217 0 22319
    217 0 21954
    217 0 21244
    217 0 21741
    217 0 21744
    217 0 21739
    217 0 21408
    227 0 21423
    230 0 21286
    230 1 21300
    end
    label values visits visits
    label def visits 0 "first episode visit", modify
    label def visits 1 "unrelated episode visit", modify


  • #2
    Code:
    bys id (date): g count = _n if visits!=1
    drop if count>1

    Comment

    Working...
    X