Announcement

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

  • Calculating censorship date for survival analysis

    I'm doing survival analysis and trying to calculate the end of follow-up date for each patient. Follow-up is to be censored when an individual discontinues their initial exposure (defined as no prescription for at least 3 months), switches between exposures or adds in another exposure to their initiating treatment. To switch or add in another exposure is defined as 2 consecutive prescriptions for at least 90 days of an exposure different to the initial treatment.

    Quite a complex method to determine end of follow-up/censorship. Is there anyone that could help? A small anonymised sample set below for you to have a go with:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte ID int(startdate prscdate) byte exposure
    1 21531 21531 8
    1 21531 21574 8
    1 21531 21592 8
    1 21531 21634 8
    1 21531 21691 8
    1 21531 21808 8
    1 21531 21840 8
    1 21531 21886 8
    1 21531 21921 4
    1 21531 21931 4
    2 16764 16764 6
    2 16764 16790 6
    2 16764 16820 6
    2 16764 16820 3
    2 16764 16859 3
    3 15077 15077 6
    3 15077 15103 6
    3 15077 15189 6
    3 15077 15245 6
    3 15077 15301 6
    4 17303 17303 1
    4 17303 17322 1
    4 17303 17336 1
    4 17303 17367 1
    4 17303 17422 1
    5 15508 15508 6
    5 15508 15530 6
    5 15508 15547 6
    5 15508 15547 2
    5 15508 15564 2
    end
    format %td startdate
    format %td prscdate
    label values exposure AHT_drugclass
    label def AHT_drugclass 1 "ACEI", modify
    label def AHT_drugclass 2 "ARB", modify
    label def AHT_drugclass 3 "BB", modify
    label def AHT_drugclass 4 "CCB", modify
    label def AHT_drugclass 6 "Diuretics", modify
    label def AHT_drugclass 8 "a1-blocker", modify
    Thank you

  • #2
    I'm not sure I fully understand your criteria here. But see if this does it. Note that I am assuming that "three months" in the first condition is to be understood as the same thing as 90 days in the second condition. I have implemented this as finding the earliest prscdate following which there is no subsequent prescription for the initial exposure for 90 days. (If that is correct, it is a simpler single condition that encompasses both conditions in your definition in #1.)

    Code:
    gen long obs_no = _n
    preserve
    keep ID prscdate exposure
    by ID (prscdate), sort: keep if exposure == exposure[1]
    tempfile initial_exposure_rxs
    save `initial_exposure_rxs'
    
    restore
    rangejoin prscdate 0 90 using `initial_exposure_rxs', by(ID)
    by ID, sort: egen wanted = min(cond(missing(prscdate_U), prscdate, .))
    format wanted %td
    by obs_no, sort: keep if _n == 1
    -rangejoin- is by Robert Picard, and is available from SSC. To use it, you must also install -rangestat-, by Robert Picard, Nick Cox and Roberto Ferrer, also available from SSC.

    By the way, I don't know what you mean by adding an additional exposure here. There is nothing in the structure of the data set that seems to allow for that. So I have ignored that part of it in any case.

    Comment


    • #3
      It dawns on me that in the solution proposed in #2, I ignored the condition that the 90 period with different exposure from the original should consist of 2 or more prescriptions. To implement that requires changing only one line:
      Code:
      by ID, sort: egen wanted = min(cond(missing(prscdate_U) & exposure[_n+1] != exposure[1], prscdate, .))
      I also could not discern from the original post whether the date wanted is the date where the condition is first met, or is 90 days after that. The code assumes the former. If the latter, an additional line of code to -replace wanted = wanted + 90- is all that is needed.

      Comment


      • #4
        Please accept my apologies for the delayed reply. I shelved this analysis for a few month but have come back to it and your updated command in #3 and #2 all worked perfectly for me.

        Thank you very much Clyde.

        Comment

        Working...
        X