set iterlog off set scheme s1color /* A first example */ webuse stan3, clear list id year age t1 surger transplant posttran died in 99/104, sepby(id) stset t1, failure(died) id(id) stdescribe sts graph sts graph, by(surgery) risktable stci stci, by(posttran) stsum, by(posttran) sts test posttran /* Cox proportional hazards model */ webuse drugtr, clear describe studytime-age stset sts graph, hazard noboundary saving(haz, replace) ylabel(, angle(horizontal)) sts graph, surv saving(surv, replace) ylabel(, angle(horizontal)) graph combine surv.gph haz.gph, cols(1) stcox drug age stcurve, survival stcurve, survival at1(drug=0 age=50) at2(drug=0 age=60) /// at3(drug=1 age=50) at4(drug=1 age=60) /// xlabel(,grid) ylabel(0(0.1)1, angle(horizontal)) stcurve, hazard at1(drug=0) at2(drug=1) * Diagnostics * estat concordance, gheller estat phtest, detail estat phtest, plot(drug) stphplot, by(drug) stcoxkm, by(drug) stcox drug age, tvc(age) /* Shared-frailty models */ webuse catheter, clear sort patient time list patient time infect age female in 1/6, sep(2) stset time, fail(infect) stcox age female, shared(patient) noshow predict nu, effects sort nu list patient nu in 1/2 list patient nu in 75/L display exp(-2.448707) display exp(0.5187159) /* Competing risks regression models */ webuse pneumonia, clear rename (died discharged) (carrest death) label data "Fictional cardiac arrest data" label variable carrest "1 if cardiac arrest" label variable death "1 if died" save cardiac, replace use cardiac, clear describe stset ndays, id(id) failure(carrest) sts graph, survival xlabel(, grid) stcrreg age pneumonia, compete(death) noshow stcurve, cif at1(pneumonia=0) at2(pneumonia=1) /* Parametric survival models */ webuse cancer, clear replace drug = drug==2 | drug==3 label variable drug "Drug type" save cancer2, replace clear use cancer2 describe studytime-age stset studytime, failure(died) streg age i.drug, distribution(llogistic) tratio noshow stcurve, hazard stcurve, surv at1(drug = 0) at2(drug = 1) ylabels(0 .5 1) margins drug, at(age=(50(1)65)) noatlegend marginsplot /* Interval-censored survival-time data */ webuse cosmesis, clear describe sort ltime rtime list in 4/7, sep(2) list in 93/94 stintreg i.treat, interval(ltime rtime) distribution(weibull) estat gofplot predict mstime, mean time tabulate treat, summarize(mstime) means freq