--------------------------------------------------------------------------------------- name: log: C:\MyDocs\MPH\LectureNotes\ClassDoLogData\Poisson\8.8.2.Survival_to_Person > Years.log log type: text opened on: 22 Jan 2010, 14:56:03 . * 8.8.2.Survival_to_PersonYears.log . * . * Convert survival data to person-year data. . * The survival data set must have the following variables: . * id = patient id, . * age_in = age at start of follow-up, . * age_out = age at end of follow-up, . * fate = fate at exit: censored = 0, dead = 1, . * treat = treatment variable. . * . * The person-year data set created below will contain one . * record per unique combination of treatment and age. . * . * Variables in the person-year data set that must not be in the . * original survival data set are . * age_now = an age of people in the cohort, . * pt_yrs = number of patient-years of observations of people . * who are age_now years old, . * deaths = number of events (fate=1) occurring in pt_yrs of . * follow-up for this group of patients. . * . use C:\WDDtext\8.8.2.Survival.dta, clear . list +--------------------------------------+ | id age_in age_out treat fate | |--------------------------------------| 1. | A 1 4 1 0 | 2. | B 3 5 1 1 | 3. | C 3 6 2 0 | 4. | D 2 3 2 1 | 5. | E 1 3 2 1 | +--------------------------------------+ . generate exit = age_out + 1 . stset exit, id(id) enter(time age_in) failure(fate) id: id failure event: fate != 0 & fate < . obs. time interval: (exit[_n-1], exit] enter on or after: time age_in exit on or before: failure ------------------------------------------------------------------------------ 5 total obs. 0 exclusions ------------------------------------------------------------------------------ 5 obs. remaining, representing 5 subjects 3 failures in single failure-per-subject data 16 total analysis time at risk, at risk from t = 0 earliest observed entry t = 1 last observed exit t = 7 . stsplit age_now, at(0(1)6) (11 observations (episodes) created) . list id age_in age_out treat fate exit age_now +-------------------------------------------------------+ | id age_in age_out treat fate exit age_now | |-------------------------------------------------------| 1. | A 1 4 1 . 2 1 | 2. | A 1 4 1 . 3 2 | 3. | A 1 4 1 . 4 3 | 4. | A 1 4 1 0 5 4 | 5. | B 3 5 1 . 4 3 | |-------------------------------------------------------| 6. | B 3 5 1 . 5 4 | 7. | B 3 5 1 1 6 5 | 8. | C 3 6 2 . 4 3 | 9. | C 3 6 2 . 5 4 | 10. | C 3 6 2 . 6 5 | |-------------------------------------------------------| 11. | C 3 6 2 0 7 6 | 12. | D 2 3 2 . 3 2 | 13. | D 2 3 2 1 4 3 | 14. | E 1 3 2 . 2 1 | 15. | E 1 3 2 . 3 2 | |-------------------------------------------------------| 16. | E 1 3 2 1 4 3 | +-------------------------------------------------------+ end of do-file . help collapse . collapse (count) pt_yrs = age_in (sum) deaths = fate, by(treat age_now) . list +-----------------------------------+ | treat age_now pt_yrs deaths | |-----------------------------------| 1. | 1 1 1 0 | 2. | 1 2 1 0 | 3. | 1 3 2 0 | 4. | 1 4 2 0 | 5. | 1 5 1 1 | |-----------------------------------| 6. | 2 1 1 0 | 7. | 2 2 2 0 | 8. | 2 3 3 2 | 9. | 2 4 1 0 | 10. | 2 5 1 0 | |-----------------------------------| 11. | 2 6 1 0 | +-----------------------------------+ . list +-----------------------------------+ | treat age_now pt_yrs deaths | |-----------------------------------| 1. | 1 1 1 0 | 2. | 1 2 1 0 | 3. | 1 3 2 0 | 4. | 1 4 2 0 | 5. | 1 5 1 1 | |-----------------------------------| 6. | 2 1 1 0 | 7. | 2 2 2 0 | 8. | 2 3 3 2 | 9. | 2 4 1 0 | 10. | 2 5 1 0 | |-----------------------------------| 11. | 2 6 1 0 | +-----------------------------------+ . exit, clear