Announcement

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

  • Keep track of patients across observations

    Hello everyone,

    I have a large dataset with 10 million observations of hospital admissions. I need to follow up on (or keep track of) patients who had a specific admission of interest (IndexAdmission) across all subsequent observations/admissions.

    In the small example below, I need to track patients with IDs 9428683, 5779720, 3324298, 10020366, and 6020031, and flag them throughout the entire dataset.

    I would greatly appreciate any help, as I am currently stuck with this task.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long PatientID int IndexAdmission
    9428683 1
    5779720 1
    3324298 1
    10020366 1
    6020031 1
    9597902 0
    8664997 0
    9428683 0
    13746335 0
    6354018 0
    9428683 0
    4510983 0
    1164266 0
    8572130 0
    3324298 0
    12393016 0
    6164436 0
    3324298 0
    4764362 0
    9428683 0
    5701333 0
    9428683 0
    end
    Best regards

  • #2
    Code:
    gen byte flag = inlist(PatientID, 9428683, 5779720, 3324298, 10020366, 6020031)

    Comment


    • #3
      Thank you so much Clyde for your reply. It is no problem to do it by hand for the small sample here, but this method is not possible in the real dataset containing 10 million observations and hundreds of different index patients to be flagged. I am looking for a programmatical way to find/flag all those IDs who have at least one occurence of IndexAdmission = 1 in the whole dataset. Thank you very much!

      Comment


      • #4
        Originally posted by Tim Wallner View Post
        . . . in the real dataset containing 10 million observations and hundreds of different index patients to be flagged. I am looking for a programmatical way to find/flag all those IDs who have at least one occurence of IndexAdmission = 1 . . .
        Maybe
        Code:
        keep if IndexAdmission == 1
        contract PatientID, freq(discard)
        merge 1:m PatientID using <original master dataset>, keep(match) nogenerate noreport

        Comment


        • #5
          FAQ . . Creating variables recording whether any or all possess some char.
          . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
          2/03 How do I create a variable recording whether any
          members of a group (or all members of a group)
          possess some characteristic?
          http://www.stata.com/support/faqs/data-management/
          create-variable-recording/


          Code:
          egen wanted = max(IndexAdmission == 1), by(PatientID) 
          
          * keep if wanted

          Comment


          • #6

            Code:
            egen wanted = max(IndexAdmission), by(PatientID)
            should work with the data example, but the code in #5 is deliberately a little more circumspect, to deal with e.g. missing values too.

            Comment

            Working...
            X