Announcement

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

  • Using information from the subsequent observation to generate a variable for the current observation

    Dear Statalist

    I am working with a data set containing patients (patid) with repeat prescriptions (RXnumber) with the prescription issue date (RXdate) and am trying to generate a treatment exposure period.

    When repeat prescriptions are within 60 days of each other (Repeat <60) then they fall within the same treatment episode (TE).

    One-off prescriptions [gaps of more than 60 days between prescriptions (Repeat > 60)] are assumed to have an exposure period of 60 days and form their own TE.

    I need to use the subsequent observation in the variable Repeat to set the exposure period for the one-off prescriptions (60 days).

    This is because I cannot distinguish one-off prescriptions from the first prescription of a treatment episode (with more than one prescription).


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long patid int RXnumber float(RXdate Repeat TE)
    1 1 18682   0 1
    1 2 18711  29 1
    1 3 18744  33 1
    1 4 18774  30 1
    1 5 18806  32 1
    1 6 18821  15 1
    1 7 18849  28 1
    1 8 18876  27 1
    1 9 18903  27 1
    2 1 17365   0 1
    2 2 17847 482 2
    2 3 17870  23 2
    3 1 19124   0 1
    3 2 19883 759 2
    3 3 20135 252 3
    3 4 20170  35 3
    3 5 20186  16 3
    end
    format %td RXdate
    I will then be using the median Repeat value in a specific TE with more than one prescription (at patient level). This will be the exposure period for the last prescription in a TE with more than one prescription.

    I would be extremely grateful for any suggestions.

    Please let me know if you require any further clarification.

    Many thanks

    Debabrata

  • #2
    Hi Debabrata,

    I'm not sure I understood, but you want to find all observations 60 days from the first, assign those to a group of treatment, and if this patient (patid) appears again after those 60 days, it gets assigned a new treatment? If so, try the code below:

    Code:
    sort patid RXnumber
    bysort patid: replace timedif = (RXdate - RXdate[1])
    gen treatment = timedif
    recode treatment (0/60 = 1) (61/120 = 2) (121/180 = 3) (181/240 = 4) (241/300 = 5) (301/360 = 6) (361/420 = 7) (421/480 = 8) (481/540 = 9) (541/600 = 10) (601/660 = 11) (661/720 = 12) (721/780 = 13) (781/840 = 14) (841/900 = 15) (901/960 = 16) (961/1020 = 17) (1021/1080 = 18) (1081/1140 = 19) (1141/1200 = 20)

    Comment


    • #3
      the question is not clear to me; what if a person has 3 prescriptions, each 45 days apart; then #1 and #2 are part of the same episode and #2 and #3 are part of the same episode but #1 and #3 are not part of the same episode

      Comment


      • #4
        Hello. Firstly thank you very much to you both for your replies and suggestions.It is hugely appreciated.

        I will attempt to clarify:

        Each patient has their own patid so I am following a patient's prescription (RX) history for the same medication. .

        The Repeat variable is the number of days between consecutive prescription dates (i.e. time between RXnumber 1 and RXnumber 2; RXnumber 2 and Rxnumber 3; etc).

        Repeat =0 for each patient's first prescription as Repeat measures the time gap between consecutive prescriptions.

        If Repeat is less than 60 days then these prescriptions fall within the same treatment episode (TE).

        If Repeat is more than 60 days then this signifies the beginning of a new TE.


        My next step is I am planning on calculating the treatment exposure period for each treatment episode for each patient.


        For treatment episodes with more than one prescription I will sum the time between prescriptions (Repeat) and add the median Repeat value (in the TE) to this total.


        My question is with regards to generating the treatment exposure period for treatment episodes with only one prescription.

        For treatment episodes with one prescription the treatment exposure period will be set to 60 days (an assumption).

        However the only way I think I can identify treatment episodes with one prescription is when Repeat > 60 which is listed with the consecutive prescription. This is where I am unsure what to do.

        So to answer the questions posed:

        Igor Paploski:

        It is for the same treatment and the treatment episodes have already been assigned.

        Rich Goldstein:

        If a person has 3 prescriptions, each 45 days apart then 1, 2 and 3 are part of the same TE. This is because Repeat < 60.

        Best wishes

        Debabrata

        Comment

        Working...
        X