*! version 1.0.0 11 apr 1997 STB-37 ssa9 program define stcoxe version 5.0 local options "noHR Level(integer $S_level) noSHow" parse "`*'", parse(" ,") if "`1'"=="" | "`1'"=="," { if "$S_E_cmd"!="stcoxe" { error 301 } parse "`*'" } else { st_is local t0 : char _dta[st_t0] local t : char _dta[st_t] local d : char _dta[st_d] local wt : char _dta[st_wt] if "`wt'" != "" { error 135 } local varlist "req ex" local if "opt" local in "opt" local options "`options' STrata(string)" parse "`*'" if "`strata'"!="" { unabbrev `strata' local strata "$S_1" } tempvar touse event mark `touse' `if' `in' markout `touse' `varlist' if "`strata'" != "" { markout `touse' `strata', strok local stopt "strata(`strata')" } st_show `show' preserve quietly { keep if `touse' keep `varlist' `t0' `t' `d' `strata' if "`d'"=="" { tempvar `d' gen byte `d' = 1 char _dta[st_d] "`d'" } st_rpool `event', `stopt' nopreserve clogit `d' `varlist', group(`event') local obs = _result(1) local ll = _result(2) local chi2 = _result(6) local mdf = _result(3) } tempname b v mat `b' = get(_b) mat `v' = get(VCE) mat post `b' `v', depname(`t') obs(`obs') global S_E_ll = _result(2) global S_E_chi2 = _result(6) global S_E_mdf = _result(3) global S_E_svn "`strata'" global S_E_t0 "`t0'" restore st_hc `touse' global S_E_cmd = "stcoxe" } di if "$S_E_svn"=="" { local h "Cox regression" } else local h "Stratified Cox regr." if "$S_E_t0"=="" { local t0 0 } else local t0 $S_E_t0 di _n in gr "`h' (exact method for ties) -- entry time `t0'" _n st_hcd di if "`hr'"=="" { local ef "eform(Haz. Ratio)" } if `level'<10 | `level'>99 { local level 95 } mat mlout, `ef' level(`level') if "$S_E_svn" != "" { local ttl "Stratified by $S_E_svn" local skip = 78 - length("`ttl'") di in gr _skip(`skip') "`ttl'" } end exit program define Expand /* newvar */ local event "`1'" local d : char _dta[st_d] local t : char _dta[st_t] local t0 : char _dta[st_t0] if "`t0'"=="" { local t0 0 } sort `t' `d' by `t': gen `event' = cond(_n==_N & `d'!=0,-1,.) sort `event' `t' count if `event' == -1 local nevent = _result(1) local nobs = _N local ev 1 while `ev' <= `nevent' { local nobs1 = _N + 1 expand 2 if `t0'<`t'[`ev'] & `t'>=`t'[`ev'] in 1/`nobs' replace `event' = `ev' in `nobs1'/l replace `d' = 0 if `t'>`t'[`ev'] in `nobs1'/l local ev = `ev' + 1 } drop if `event'==-1 | `event'==. end