Announcement

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

  • Longitudinal administrative health data - flag claimants who received the same treatment accross all observations

    Greetings,

    I have a longitudinal administrative health dataset consisting of over 400,000 observations. Patients are represented by an alpha numeric identification number and have between 1 and 7000+ administrative claims. I would like to identify all patient identification numbers that received the same treatment across all observations. I have generated a variable that identifies the treatment of interest as 1 for each observation, but I have not been able to figure out how to identify Patients who received the treatment across all observation.

    Here is an example dataset to help illustrate my problem:

    ID TRT

    a1 1

    a1 0

    a1 1

    a2 1

    a3 1

    a3 1

    a4 1

    a4 1

    a4 1

    a5 0

    a5 0

    In the example provided ID# a2-a4 received the same treatment.

    Thanks in advance.

    Robert

  • #2
    If I'm reading your question right the idea is that you want to identify individuals who have all 1s for your TRT variable. You can use by to look within your ID groups to determine the total observations with the treatment and compare this to total number of observations. Try something like this:

    Code:
    bysort ID: egen tot_trt=sum(TRT)
    bysort ID: gen all_same=(tot_trt==_N)

    Comment


    • #3
      See also https://www.stata.com/support/faqs/d...ions-in-group/ from which


      Code:
      bysort ID (TRT) : gen allone = TRT[1] & TRT[_N]

      Comment

      Working...
      X