Announcement

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

  • Identify and tag first obs value in variable

    I have a categorical variable program_value for a given health services used on that date. Ex. someone might have 1/1/22 program_value = hospital, 1/3/22 program_value = gp, 1/5/22 program_value=hospital
    I want to tag the first appearance of "hospital" for each id. I'll be using this to compare service use before and after first hospital.

    This is what didn't work:

    gen prog_hospital=1 if program_value=="hospital"
    egen first_hospital=tag(prog_hospital)

    One more layer is that the timeframe resets every 30 days, so a hospital on 1/5/22 and 2/7/22 would both be first hospital, but if it were 1/5/22 and 1/7/22, only the 1/5 would be tagged as first hospital.

    variables:
    id = subject id
    program_value = health service (hospital, gp, outpatient, detox)
    date = date of health service use

  • #2
    Paige Cohen could you please provide a small extract of your data using the -dataex- command in Stata?

    And welcome to Statalist! You might want to look through the Statalist FAQ on tips on how to pose questions more effectively.

    Comment


    • #3
      Hemanshu Kumar thanks for the tip!
      Code:
      input long id str63 program_value float admitdate
      5871564 "ZSFG PC MEDICAL AT B5 RFPC"                              21823
      5871564 "ZSFG PC BEHAVIORAL HEALTH AT B5 RFPC"                    21866
      5871564 "ZSFG PC MEDICAL AT B5 RFPC"                              21949
      5871564 "DPH PC MEDICAL CASTRO MISSION HC"                        21805
      5871564 "DPH PC MEDICAL CASTRO MISSION HC"                        21893
      5871564 "DPH PC MEDICAL CASTRO MISSION HC"                        21929
      5871564 "DPH PC MEDICAL CASTRO MISSION HC"                        21973
      end
      format %td admitdate
      for example, i'd like to tag the first instance of "castro mission" for every 30-day period
      Last edited by Paige Cohen; 12 Oct 2022, 15:38.

      Comment

      Working...
      X