version 10.0 log using 8.8.2.Survival_to_PersonYears.log, replace * 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 generate exit = age_out + 1 stset exit, id(id) enter(time age_in) failure(fate) stsplit age_now, at(0(1)6) list id age_in age_out treat fate exit age_now sort treat age_now collapse (count) pt_yrs=age_in (sum) deaths=fate, by (treat age_now) list treat age_now pt_yrs deaths save 8.8.2.Person-Years.dta, replace log close