version 9 set scheme sj capture log close set more off log using ehe1.log, replace use rrdat1, clear * 1st option: use stsplit gen des = tfin ~= ti /*destination state*/ gen tf = tfin - tstart + 1 /*ending time*/ gen newid = _n stset tf, failure(des) id(newid) /*define single episode data*/ stsplit time, at(0 (12) 96) /*split records*/ tab time, ge(t) /*generate time dummies*/ stset tf, failure(des) id(newid) /*define single episode data*/ streg t1 t2 t3 t4 t5 t6 t7 t8 t9, dist(exp) nohr noconstant /*fit parametric survival model*/ predict hazard, hazard /*obtain predictions*/ line hazard _t, sort title("Piecewise Constant Exponential Rate") /// xtitle("analysis time") saving("Figure 5_2_1",replace) drop time t1-t9 hazard stjoin * 2nd option: use stpiece ssc install stpiece /*install wrapper to estimate piecewise-constant hazard rate models*/ stset tf, failure(des) id(newid) /*define single episode data*/ stpiece, tp(0(12)96) nohr /*fit piecewise constant exponential model*/ log close