📄 gompertz.ado
字号:
*! version 1.3.7 21jun2005
program define gompertz, eclass byable(recall) prop(ml_score)
version 7.0
if replay() {
if `"`e(cmd)'"' != "gompertz" { error 301 }
if _by() { error 190 }
syntax [, Level(cilevel) noCOEF noHEADer HR]
if "`e(gamma)'"=="" {
local ancilla = "anc"
}
}
else {
syntax [varlist] [if] [in] [fweight pweight iweight] /*
*/ [, noCOEF CLuster(varname) Dead(varname numeric) /*
*/ DEBUG FROM(string) noHEADer HR MLMethod(string) /*
*/ MLOpt(string) noCONstant /*
*/ Level(cilevel) noLOg STrata(varname) /*
*/ OFFset(varname numeric) ANCillary(varlist) /*
*/ Robust SCore(string) T0(varname numeric) SKIP *]
if _by() {
_byoptnotallowed score() `"`score'"'
}
tokenize `varlist'
local t `1'
mac shift
local rhs `*'
if "`strata'"~="" {
if "`ancillary'"~="" {
noi di as err /*
*/ "options strata() and ancillary()" /*
*/ " may not be specified together"
exit 198
}
qui xi, prefix(_S) i.`strata'
local rhs `rhs' _S*
local ancillary _S*
}
if "`cluster'"!="" {
local cluopt cluster(`cluster')
}
if "`from'"!="" { local iniopt init(`from') }
if "`mlmethod'" == "" { local mlmetho "d2" }
if "`offset'" !="" { local offopt offset(`offset') }
mlopts options, `options'
if "`score'" != "" {
local n : word count `score'
if `n'==1 & substr("`score'",-1,1)=="*" {
local score = /*
*/ substr("`score'",1,length("`score'")-1)
local score `score'1 `score'2
local n 2
}
if `n' != 2 {
di as err /*
*/ "score() invalid: two new variable names required"
exit 198
}
confirm new var `score'
local scopt "score(`score')"
}
if "`weight'" != "" {
tempvar wv
qui gen double `wv' `exp'
local w [`weight'=`wv']
}
tempvar touse
mark `touse' `w' `if' `in'
markout `touse' `t' `rhs' `dead' `t0' `offset'
markout `touse' `cluster', strok
if "`dead'" != "" {
local sdead "`dead'"
capture assert `dead'==0 | `dead'==1 if `touse'
if _rc {
tempvar mydead
qui gen byte `mydead' = `dead'!=0 if `touse'
local dead "`mydead'"
}
}
else {
tempvar dead
qui gen byte `dead'=1
local sdead 1
}
if "`t0'" == "" {
local t0 0
}
capture assert `t0' < `t' if `touse'
if _rc {
di as err "`t0' >= `t' in some obs."
exit 498
}
_rmcoll `rhs' `w' if `touse', `constant'
local rhs "$S_1"
global S_1
global EREGd `dead'
global EREGt0 `t0'
if "`log'"!="" { local nlog="*" }
tempvar num den
tempname bc0
quietly {
if "`weight'"=="aweight" | "`weight'"=="pweight" {
tempvar wvn
summ `wv' if `touse', meanonly
gen double `wvn' = `wv'/r(mean) if `touse'
local wvngen 1
}
else if "`weight'"!="" {
local wvn `wv'
}
else {
local wvn 1
}
gen double `num' = sum(`wvn'*`dead'*`touse')
gen double `den' = sum(`wvn'*(`t'-$EREGt0)*`touse')
local cons = ln(`num'[_N]/`den'[_N])
drop `num' `den'
gen double `num' = `wvn'*ln(`t') if `touse' & `dead'
replace `num' = sum(`num')
global EREGa = `num'[_N]
drop `num'
if "`wvngen'"!="" { drop `wvn' }
mat `bc0' = ( `cons', 0 ) /* GAMMA = 0.1 */
mat colnames `bc0' = $EREGt:_cons gamma:_cons
}
local search search(off)
if "`constant'"!="" {
local skip = "skip"
local search search(quietly)
`nlog' di as txt "Fitting full model:"
}
if "`rhs'" != "" & "`skip'"=="" {
`nlog' di ""
`nlog' di as txt "Fitting constant-only model:"
ml model `mlmetho' gomp_lf (`t': `t'=, `offopt' ) /*
*/ (gamma: `ancillary') `w' if `touse', /*
*/ init(`bc0') /*
*/ missing collin nopreserve wald(0) `mlopt' /*
*/ max search(quietly) noout `log' `options' /*
*/ `robust'
local cont continue
`nlog' di ""
`nlog' di as txt "Fitting full model:"
}
else {
local cont wald(1)
}
ml model `mlmetho' gomp_lf /*
*/ (`t': `t'=`rhs', `offopt' `constant') /*
*/ (gamma: `ancillary') `w' if `touse', `cont' noout /*
*/ `robust' `cluopt' `scopt' `iniopt' `mlopt' /*
*/ missing collin nopreserve /*
*/ max `search' `log' `options'
if "`e(wtype)'" != "" {
est local wexp `"`exp'"'
}
est local title2 "log relative-hazard form"
est local predict gomper_p
est local cmd gompertz
est local t0 `t0'
est local dead `sdead'
global S_E_cmd gompertz
}
global EREGw
global EREGd
global EREGt
global EREGt0
global EREGa
if "`ancillary'" =="" & "`ancilla'"=="" {
est scalar gamma= [gamma]_b[_cons]
est local stcurve="stcurve"
}
if "`coef'"=="" {
if "`hr'"!="" {
local hr "eform(Haz. Ratio)"
}
else { local hr }
if "`ancillary'" =="" & "`ancilla'"=="" {
if "`header'" == "" {
di _n as txt /*
*/ "Gompertz regression -- entry time `e(t0)'"
}
version 9: ///
ml di, `header' level(`level') `hr' first plus ///
title(`e(title2)')
local bg "[gamma]_b[_cons]"
local sg "[gamma]_se[_cons]"
local iz = invnorm(1-(1-`level'/100)/2)
local ll = `bg'-`sg'*`iz'
local uu = `bg'+`sg'*`iz'
local zz = `bg'/`sg'
di as txt in smcl /*
*/ " gamma {c |} " as res %9.0g `bg' /*
*/ " " %9.0g (`sg') " " %8.2f (`zz') /*
*/ " " %7.3f (normprob(-abs(`zz'))*2) /*
*/ _col(58) %9.0g (`ll') " " %9.0g (`uu')
di as txt in smcl "{hline 13}{c BT}{hline 64}"
est scalar gamma= [gamma]_b[_cons]
ml_footnote
}
else {
if "`header'" == "" {
di _n as txt /*
*/ "Gompertz regression -- entry time `e(t0)'"
}
version 9: ///
ml di, `header' level(`level') `hr' ///
title(`e(title2)')
}
}
end
exit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -