⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weibull_c.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
字号:
*! version 1.4.17  21jun2005
program define weibull_c, eclass byable(recall)
	version 7
	if replay() {
		if `"`e(cmd)'"' != "weibull" { error 301 } 
		if _by() { error 190 }
		syntax [, Level(cilevel) noCOEF noHEADer TR HR ]
		if "`e(aux_p)'"=="" {
			local ancillary 1
		}
	}
	else {
		syntax [varlist] [if] [in] [fweight pweight iweight] /*
			*/ [, noCOEF CLuster(varname) Dead(varname numeric)/*
			*/ DEBUG FROM(string) noHEADer MLMethod(string) /*
			*/ MLOpt(string) noCONstant HAzard HR STrata(varname) /*
			*/ Level(cilevel) noLOg TRANS /*
			*/ OFFset(varname numeric) ANCillary(varlist) /*
			*/ Robust SCore(string) T0(varname numeric) SKIP TR *]
		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 "`weight'" == "pweight" | "`robust'`cluster'" != "" {
			local robust robust
		}

		if "`mlmethod'" == "" { local mlmetho = "d2" }
		if "`offset'" !="" { local offopt = "offset(`offset')" }
		mlopts mloptions, `options'
		if "`hazard'"!="" {
			if "`tr'"!="" {
				di as err "tr invalid with hazard option"
				exit 198
			}
		}
		else if "`hr'"!="" {
			local hazard "hazard"
		}
		
		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']
		}
		/* Mark sample. */
		marksample touse
		markout `touse' `t0' `dead' `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
		}
		else {
			local t0opt="t0(`t0')"
		}
		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 "`r(varlist)'"
		global S_1

		if "`from'" != "" { 
				local iniopt init(`from') 
		}
		tempname b0 
		if "`constant'"=="" {
			qui weibull_s `t' `w' if `touse', /*
				*/ dead(`dead') `t0opt' `hazard'
			matrix `b0' = e(b)
		}

		global EREGd `dead'
		global EREGt `t'
		global EREGt0 `t0'

		local maxlf weib2_lf 
		if "`hazard'"=="" {
			local maxlf weib1_lf 
		}
		if "`log'"!="" { local nlog="*" }
		tempvar mysamp num den
		tempname b f V  g bc0
		quietly { 
			if "`weight'"=="aweight" | "`weight'"=="pweight" {
				tempvar wvn
				summ `wv' if `touse', meanonly 
				gen double `wvn' = `wv'/r(mean)
				local wvngen 1
			}
			else if "`weight'"!="" {
				local wvn `wv'
			}
			else {
				local wvn 1
			}
			gen double `num' = `wvn'*ln(`t') if `touse' & `dead'
			replace `num' = sum(`num') 
			global EREGa = `num'[_N]
			if "`trans'" ~="" {
				global EREGa = 0
			}	
			drop `num' 
			if "`wvngen'"!=""  { drop `wvn' }
		}
		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' `maxlf' (`t': `t'=, `offopt') /*
				*/ (ln_p: `ancillary') `w' if `touse', /*
				*/ init(`b0') /*
				*/ missing collin nopreserve wald(0) `mlopt' /*
				*/ max search(quietly) noout `log' /*
				*/ `mloptions' `robust'
			local cont continue
			`nlog' di ""
			`nlog' di as txt "Fitting full model:"
		}
		else {
			local cont wald(1)
		}
		ml model `mlmetho' `maxlf' /*
			*/ (`t': `t'=`rhs' , `offopt' `constant') /*
			*/ (ln_p: `ancillary') `w' if `touse', `cont'/*
			*/ `robust' `cluopt' `scopt' `mlopt' /*
			*/ missing collin nopreserve `iniopt' /*
			*/ max `search' `log' `mloptions' 
		if "`e(wtype)'" != "" {
			est local wexp `"`exp'"'
		}
		est local title2 "log relative-hazard form"
		if "`hazard'"=="" {
			est local title2 "accelerated failure-time form"
			est local frm2 "time"
		}
		else    est local frm2 "hazard"
		est local predict weibul_p
		est local cmd weibull 
		est local by_weibull_c by_weibull_c
		est local t0 "`t0'"
        	est local dead `sdead'
	}
	global EREGw
	global EREGd
	global EREGt
	global EREGt0
	global EREGa

	if "`ancillary'" =="" {
		local bg "[ln_p]_b[_cons]"
		est scalar aux_p = exp(`bg')        
		est local stcurve="stcurve"
	}
	if "`coef'"=="" {
		if "`hr'"!="" {
			local eform "eform(Haz. Ratio)"
		}
		else if "`tr'"!="" {
			local eform "eform(Tm. Ratio)"
		}

		if `"`tr'"'!=`""' {
			local hr `"eform(Tm. Ratio)"'
                }
		if "`ancillary'" =="" {
			if "`header'" == "" {
				di _n as txt /*
				*/ "Weibull regression -- entry time `e(t0)'"
			}
			version 9: ///
			ml di, `header' `eform' level(`level') first plus ///
				title(`e(title2)')
			_diparm ln_p, level(`level')
			di as txt in smcl "{hline 13}{c +}{hline 64}"
			_diparm ln_p, level(`level') exp label("p")
       			_diparm ln_p, /*
			*/ level(`level') f(exp(-@)) d(exp(-@)) label("1/p")
			di as txt in smcl "{hline 13}{c BT}{hline 64}
			ml_footnote
		}
		else {
			if "`header'" == "" {
				di _n as txt /*
				*/ "Weibull regression -- entry time `e(t0)'"
			}
			version 9: ///
			ml di, `header' `eform' level(`level') ///
				title(`e(title2)')
		}
	}
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -