Announcement

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

  • Question about tagging and keep if()

    I have a dataset with millions of patient encounters. In this data set some patients will have multiple encounters depending on return to hospital etc. every patient has a unique ID number, which may appear several times in the dataset due to repeat attendances to hospital

    I have coded operations and diagnoses of interest, and I wish to find a way to mark the unique IDs of patients who have a given operation (delineated by a dichotomous variable 0-1 no operation-operation). I then wish to keep all presentations to hospital of this unique patent ID which has also had the given procedure coded for above. essentially in my dataset, if someone has had a given operation, I want to tag their unique ID, and then keep all of their hospital episodes in the dataset.

    What would be the best way to go about doing this

    Thanks in advance for your help.

  • #2
    https://www.stata.com/support/faqs/d...ble-recording/ should help. Something like

    Code:
    egen wanted = max(operation), by(patientid) 
    keep if wanted
    may get you started.

    Comment

    Working...
    X