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

📄 ereg.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
字号:
*! version 6.2.5  25feb2005
*  (also see ereg_lf.ado)
program ereg, eclass byable(recall) prop(ml_score)
	version 7.0, missing

	if replay() {
		if `"`e(cmd)'"'!="ereg" { error 301 }
		if _by() { error 190 }
		if `"`e(frm2)'"'=="hazard" {
			local options "HR"
		}
		else	local options "TR"
		syntax [, `options' noCOEF noHEADer Level(cilevel)]
	}
	else {
		syntax varlist(min=1) [if] [in] [fw aw pw iw/] [,  /*
		*/ CLuster(varname) noCOEF HAzard noHEADer 	/*
		*/ Level(cilevel) noLOg noCONstant /*
		*/ Dead(varname numeric) HR T0(varname numeric) /*
		*/ TR Robust SCore(string) STrata(varname) /*
		*/ OFFset(varname numeric) * ]
		if _by() {
			_byoptnotallowed score() `"`score'"'
		}

		tokenize `varlist'
		local t "`1'"
		mac shift 1 
		local rhs `*'
		if "`strata'"~="" {
			qui xi, prefix(_S) i.`strata'
			local rhs `rhs' _S*
                }
		if "`hazard'"!="" {
			if `"`tr'"'!="" {
				di as err "tr invalid with hazard option"
				exit 198
			}
		}
		else if `"`hr'"'!="" {
			local hazard "hazard"
		}

		if `"`weight'"'!="" {
			tempvar wv
			qui gen double `wv' = `exp'
			local w `"[`weight'=`wv']"'
			if `"`weight'"'=="pweight" { 
				local robust "robust"
			}
		}
		if `"`score'"'!="" {
			local isscore isscore
			local n : word count `score'
			if `n'!=1 { 
				di as err `"score() invalid"'
				exit 198 
			}
			confirm new var `score'
		}
		if `"`cluster'"'!="" {
			* unabbrev `cluster', max(1)
			* local cluster `s(varlist)'
			local robust "robust"
		}
		if `"`robust'"'!="" & `"`score'"'=="" {
			tempvar score
		}

		mlopts mlopts, `options'

		tempvar touse 
		mark `touse' `w' `if' `in'
		markout `touse' `t' `rhs' `dead' `t0' `offset'
		markout `touse' `cluster', strok

		if `"`offset'"'!="" {
			local offopt `"offset(`offset')"'
		}

		if `"`dead'"'!="" {
			* unabbrev `dead', max(1)
			* local dead `s(varlist)'
			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 {
			local sdead "1"
			tempvar dead
			qui gen byte `dead'=1
		}

		if `"`t0'"'==`""' {
			local t0 0
			local realt "`t'"
		}
		else {
			tempvar realt
			qui gen double `realt' = `t'-`t0' if `touse'
			qui compress `realt'
		}
		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			/* clear for backwards compat */

		qui count if `touse' 
		local nobs = r(N) 		/* may be reset subsequently */
		if `nobs'<2 {
			if r(N)==0 { error 2000 } 
			error 2001
		}

		if `"`weight'"' != `""' {
			qui replace `wv'=0 if !`touse'
			if `"`weight'"'==`"aweight"' {
				qui summ `wv' if `touse', meanonly
				qui replace `wv' = `wv'/r(mean) if `touse'
			}
			else if `"`weight'"'==`"fweight"' {
				qui summ `wv', meanonly
				local nobs = round(r(sum),1)
			}
			global EREGw "`wv'"
		}
		else	global EREGw "`touse'"

		global EREGd `"`dead'"'
		global EREGt `"`realt'"'

		tempvar num den
		tempname f b0

		quietly {
			replace $EREGw = 0 if $EREGw>=.
			gen double `num' = sum($EREGw*$EREGd)
			gen double `den' = sum($EREGw*$EREGt)
			local cons = ln(`num'[_N]/`den'[_N])
			if `cons'>=. {
				if `num'[_N] <= 0 {
					if `num'[_N]==0 {
						di as err "no failures"
					}
					else	di as err /*
*/ "weighted sum of failures is negative"
					exit 498
				}
				/* `den'[_N]==0 */
				di as err /*
*/ "weighted sum of exit times negative or zero"
				exit 498
			}
			drop `num' `den'
			gen double `num' = sum($EREGw*ln($EREGd*`t'))
			global EREGa = `num'[_N]
			drop `num'

			matrix `b0' = ( `cons' )
			matrix colnames `b0' = _cons
			if `"`offset'"'!="" {
				global EREGoff `offset'
				ml model d2 ereg_lf (`t': `t'=, `offopt') /*
				*/ if $EREGw, init(_cons=1) missing /*
				*/ collin nopreserve wald(0) `mlopts' /*
				*/ max search(quietly) noout `options'
				scalar `f' = e(ll)
			}
			else {
				ereg_lf 0 `b0' `f' - -
			}
			local f0 = scalar(`f')
			scalar drop `f'
		}
		if "`constant'"=="" {
			if "`offset'"=="" {
				local initopt init(_cons=`cons')
			}
			else {
				local initopt continue
			}
			local wald lf0(1 `f0')
			local search search(off)
		}
		else {
		 	local wald wald(1)
			local search search(quietly)
		}
		if "`robust'" != "" {
			local crtype crittype("log pseudolikelihood")
		}

		ml model d2 ereg_lf (`t': `t'=`rhs', `constant' `offopt') /*
			*/ if $EREGw, /*
			*/ `initopt'  /*
			*/ missing collin /* for speed */ /* 
			*/ obs(`nobs') `wald' /*
			*/ maximize `search' `log' noout nopreserve /*
			*/ `mlopts' `crtype'
		est local cmd
		global S_E_cmd

		if "`weight'" != "" {
			est local wtype "`weight'"
			est local wexp `"= `exp'"'
		}

		if `"`score'"'!=`""' {
			Getscore `score'	/* in the hazard metric */
			if `"`hazard'"'==`""' {
				qui replace `score' = -`score'
			}
			if "`isscore'"!="" {
				est local scorevars `score' 
			}
		}

		if `"`hazard'"'==`""' {
			tempname b
			mat `b' = get(_b)
			mat `b' = -1 * `b'
			est repost _b = `b'
			local title `"log expected-time form"'
		}
		else 	local title `"log relative-hazard form"'

		est local title2 `"`title'"'
		est local t0 `"`t0'"'

		if `"`robust'"'!=`""' {
			if `"`cluster'"'!=`""' {
				local cluster `"cluster(`cluster')"'
			}
			_robust `score' `w' if `touse', `cluster' nofatal
			capture test `rhs', min
			est scalar chi2 = r(chi2)
			est scalar df_m = r(df)
			est local chi2type = "Wald"
		}
		if `"`hazard'"'==`""' {
			est local frm2 `"time"'
		}
		else 	est local frm2 `"hazard"'

		est local dead `sdead'

		if 1 /* _caller()<6 */ { 	/* double save */
			global S_E_t0 `e(t0)'
			global S_E_chi2 = e(chi2)
			global S_E_mdf = e(df_m)
			global S_E_frm2 `e(frm2)'

			global S_E_ll = e(ll)
			global S_E_nobs = e(N)
			global S_E_depv `e(depvar)'
			global S_E_tdf .

			global S_E_cmd ereg
		}
		est local stcurve="stcurve"
		est local predict ereg_p
		est local cmd ereg
		mac drop EREGw EREGd EREGt EREGa EREGoff
	}

	if `"`coef'"'==`""' {
		if `"`hr'"' != `""' {
			local hr `"eform(Haz. Ratio)"'
		}
		else if `"`tr'"' !=`""' {
			local hr `"eform(Tm. Ratio)"'
		}
		if `"`header'"'==`""' {
			di _n as txt /*
			*/ `"Exponential regression -- entry time `e(t0)'"' _c
		}
		ml di, `header' `hr' level(`level') title(`e(title2)')
	}
end

program Getscore /* score */
	local sco `"`1'"'
	tempvar I
	quietly {
		_predict double `I' if $EREGw
		gen double `sco' = $EREGd-exp(`I')*$EREGt if $EREGw
	}
end
exit

globals used:

	macro EREGd	name of 0/1 dead variable
	macro EREGt	name of time variable
	macro EREGw	weight variable; 0 if obs. not used
			fweight:  0 or integer
			aweight:  0 or pos. real, sums to _N
			iweight:  0, or real,

	macro EREGa	(#) adjustment to log likelihood function

⌨️ 快捷键说明

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