📄 stcox.ado
字号:
*! version 7.0.6 16mar2005
program stcox, eclass byable(onecall) prop(swml nohr hr) sort
version 8, missing
local version : di "version " string(_caller()) ", missing:"
if replay() { /* Branch off to stcox_fr as needed */
syntax [, ESTImate *]
if "`estimate'" == "" {
if _by() {
error 190
}
if `"`e(cmd2)'"' != "stcox" {
error 301
}
if "`e(shared)'" != "" {
stcox_fr `0'
exit
}
}
}
if _by() {
local by "by `_byvars'`_byrc0':"
}
syntax [varlist(default=none)] [if] [in] [, /*
*/ FRailty(string) SHared(string) *]
if `"`shared'"' != "" | `"`frailty'"' != "" {
`by' stcox_fr `0'
exit
}
`version' `BY' _vce_parserun stcox, stdata : `0'
if "`s(exit)'" != "" {
exit
}
`by' stcox_7 `0'
exit
end
program define stcox_7, eclass byable(recall)
version 7, missing
if _caller()<6 {
if _by() { error 190 }
ztcox_5 `0'
exit
}
if replay() {
syntax [, ESTImate noHR * ]
if `"`estimate'"'=="" {
if _by() { error 190 }
if `"`e(cmd2)'"' != "stcox" {
error 301
}
local hr = cond(`"`hr'"'=="", "hr", "")
local h = cond(`"`e(strata)'"'=="", /*
*/ "Cox regression", /*
*/ "Stratified Cox regr.")
local h1="no ties"
if "`e(ties)'"=="breslow" {
local h1="Breslow method for ties"
}
else if "`e(ties)'"=="efron" {
local h1="Efron method for ties"
}
else if "`e(ties)'"=="partial" {
local h1="exact partial likelihood"
}
else if "`e(ties)'"=="marginal" {
local h1="exact marginal likelihood"
}
di _n as txt `"`h' -- `h1'"'
st_hcd
di
if "`e(prefix)'"' == "" {
cox, nohead `hr' `options'
}
else {
_coef_table, `hr' `options'
}
exit
}
}
st_is 2 analysis
local oldbaseh = cond(_caller()<7,"BASEHazard(string)","")
syntax [varlist(default=none)] [if] [in] [,CLuster(string) /*
*/ CMD ESTImate noHR Level(cilevel) Robust noSHow /*
*/ BREslow EFRon EXACTM EXACTP `oldbaseh' /*
*/ BASEHC(passthru) BASEChazard(passthru) BASESurv(passthru) /*
*/ MGale(passthru) esr(passthru) /*
*/ SCHoenfeld(passthru) SCAledsch(passthru) TVC(varlist)/*
*/ altvce(name) * ]
// NOTE: altvce() is an undocumented option set by _vce_parserun for
// the purpose of generating an improved error message when this
// command is called with an option that generates a variable along
// with an alternative <vcetype> that resamples the data.
if `"`basehazard'"' != "" {
if `"`basehc'"' != "" {
di as err /*
*/ "may not specify both basehazard() and basehc() options"
exit 198
}
local basehc `"basehc(`basehazard')"'
}
if _by() {
_byoptnotallowed basehc() `"`basehc'"'
_byoptnotallowed basechazard() `"`basechazard'"'
_byoptnotallowed basesurv() `"`basesurv'"'
_byoptnotallowed mgale() `"`mgale'"'
_byoptnotallowed esr() `"`esr'"'
_byoptnotallowed schoenfeld() `"`schoenfeld'"'
_byoptnotallowed scaledsch() `"`scaledsch'"'
}
if "`altvce'" != "" {
_prefix_vcenotallowed "`altvce'" basehc() `"`basehc'"'
_prefix_vcenotallowed "`altvce'" basechazard() `"`basechazard'"'
_prefix_vcenotallowed "`altvce'" basesurv() `"`basesurv'"'
_prefix_vcenotallowed "`altvce'" mgale() `"`mgale'"'
_prefix_vcenotallowed "`altvce'" esr() `"`esr'"'
_prefix_vcenotallowed "`altvce'" schoenfeld() `"`schoenfeld'"'
_prefix_vcenotallowed "`altvce'" scaledsch() `"`scaledsch'"'
}
local passthru `basehc' `basechazard' `basesurv' `mgale' /*
*/ `esr' `schoenfeld' `scaledsch'
local id : char _dta[st_id]
local w : char _dta[st_w]
local wt : char _dta[st_wt]
local t0 `"t0(_t0)"'
local d `"dead(_d)"'
tempvar touse
st_smpl `touse' `"`if'"' `"`in'"' `"`cluster'"'
markout `touse' `varlist'
if _by() {
qui replace `touse'=0 if `_byindex'!=_byindex()
}
if `"`wt'"'=="pweight" {
local robust `"robust"'
}
if `"`robust'"'!="" & `"`cluster'"'=="" & `"`id'"'!="" {
local cluster `"`id'"'
}
if `"`cluster'"'!="" {
local cluster `"cluster(`cluster')"'
}
if `"`tvc'"'!="" {
local tvc `"tvc(`tvc')"'
}
st_show `show'
if `"`cmd'"'!="" {
di _n as txt "-> cox _t `varlist' `w' `if' `in'," _c
di as txt " `robust' `cluster' `t0' `hr' `d' `tvc' `options'" _c
di as txt " `breslow' `efron' `exactm' `exactp' `passthru'"
exit
}
cox _t `varlist' `w' if `touse', `robust' `cluster' /*
*/ `t0' `d' `tvc' /*
*/ `options' nocoef `breslow' `efron' `exactm' `exactp' /*
*/ `passthru'
if e(N)==0 | e(N)>=. { exit 2001 }
/* inherits e() stuff from -cox- */
SaveOpt, `passthru'
global S_E_ll = e(ll) /* double save */
global S_E_chi2 = e(chi2) /* double save */
global S_E_mdf = e(df_m) /* double save */
st_hc `touse'
if "`robust'" != "" {
est local vce robust
}
est local estat_cmd stcox_estat
est local predict stcox_p
est local cmd2 "stcox"
global S_E_cmd2 "stcox" /* double save */
stcox, `hr' level(`level')
end
program define SaveOpt, eclass
syntax [, MGale(string) BASEHC(string) BASEChazard(string) /*
*/ BASESurv(string) SCHoenfeld(string) /*
*/ SCAledsch(string) ESR(string) * ]
est local mgale "`mgale'"
est local basehc "`basehc'"
est local baseh "`basedchazard'"
est local basech "`basechazard'"
est local bases "`basesurv'"
SaveNm vl_sch "`schoenfeld'" "Schoenfeld"
SaveNm vl_ssc "`scaledsch'" "scaled Schoenfeld"
SaveNm vl_esr "`esr'" "efficient score"
if "`mgale'" != "" { label var `mgale' "martingale" }
if "`basehc'"!= "" {
label var `basehc' "baseline hazard contribution"
}
if "`basesurv'" != "" { label var `basesurv' "baseline survivor" }
if "`basechazard'"!= "" {
label var `basechazard' "cumulative baseline hazard"
}
end
program define SaveNm, eclass
args name base lname
if "`base'" == "" { exit }
tempname b
mat `b' = get(_b)
local p = colsof(`b')
local names : colnames(`b')
local j = index("`base'","*")
if `j' {
local base = substr("`base'",1,`j'-1)
local i 1
while `i' <= `p' {
local iname : word `i' of `names'
label var `base'`i' "`lname' - `iname'"
local list `list' `base'`i'
local i = `i'+1
}
}
else {
tokenize `base'
local i 1
while `i' <= `p' {
local iname : word `i' of `names'
label var ``i'' "`lname' - `iname'"
local list `list' ``i''
local i = `i'+1
}
}
est local `name' `list'
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -