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

📄 arch.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 4 页
字号:
		qui tsset
		global Ttimemin = r(tmin)
		global Tadjt = r(tmax) - r(tmin)
		qui gen double `wt_e2' = .7^(`timevar'-r(tmin))*$Te2 /*
			*/ if `touse'
		sum `wt_e2'  if `touse', meanonly
		scalar `adj' = r(sum)
		sum $Te2  if `touse', meanonly
		scalar $Tsig2_0 = 0.7^$Tadjt*r(sum)/(r(N)-0) + 0.3*`adj'
		global Ts2_mayb = $Tsig2_0
	}
	else if "$Tarch0" == "xb0" | "$Tarch0" == "xb" {
		sum $Te2  if `touse', meanonly
		scalar $Tsig2_0 = r(mean)
		global Ts2_mayb = $Tsig2_0
	}

				/* ARMA priming if skipping initial obs */
	if "$Tskipobs" != "" {
		tempname touse2 tvar
		qui gen byte `tvar' = `touse'
		qui replace `tvar' = . if !`touse'
		qui gen byte `touse2' = `touse'
		markout `touse2' l(0/$Tskipobs).`tvar'
		drop `tvar'
	}
	else	{
		local touse2 `touse'
	}
	global Ttouse2 `touse2'

	qui count if `touse2'
	local nobs `r(N)'

				/* Report time gaps */
	tsreport if `touse2', report `detail'
	local gaps `r(N_gaps)'
	if `gaps' > 0 { di in gr "(note: conditioning reset at each gap)" _n }

				/* HET -- multiplicative heteroskedasticity */

	if "`het'" != "" {
		global Tmhet 1
		qui replace $Te2 = ln($Te2)
		capture regress $Te2 `het' if `touse'
		ErrCheck
		mat `T' = e(b)
					/* Harvey's (1976) adjustment */
		mat `T'[1,colsof(`T')] = `T'[1,colsof(`T')] + 1.2704     
		mat `b0' = nullmat(`b0') , `T'
		mat repost _b=`T'
		local heteqn "(HET:  `yprefix' = `het', linear )"
		local yprefix
					/* maintain name stripe */
		mat `T' = e(b)
		mat coleq `T' = HET
		local names : colfullnames `T'
		local colnams `colnams' `names'


					/* back in e^2 space for ARCH terms */
					/* Tsigma2 used temporarily */
		qui predict double $Tsigma2 if `touse' 
		qui replace $Te2 = exp($Te2 - $Tsigma2)		/* must be >0 */
		drop $Tsigma2
		local archcon "nocons"
	}
	else if !$Tarchany {
		local archcon "nocons"
		sum $Te2  if `touse', meanonly
		mat `T' = r(mean)
		mat `b0' = nullmat(`b0') , `T'
		local heteqn "(HET:  `yprefix' = )"
		local yprefix
		local colnams `colnams' SIGMA2:_cons
	}
	/* else	arch terms will have a constant for sigma2_cons	*/

					/* nonlinear terms and equation */
					/* b(|e_(t-i)| - a)		*/
					/* priming values are plug-ins	*/
					/* nesting means /` won't work  */
					/* for delayed substitution     */
	if "$Tnarch" != "" {
		tempname b
		capture local i0 = colsof(`b0')
		if _rc { local i0 0 }

		local lnum : word count $Tnarch
		tokenize $Tnarch
		local i 1
		global Tnarchex update $Tsigma2 = $Tsigma2 
		while "``i''" != "" {
			local i1 = `i0' + `i'
			if "`narchk'" == "" {
				local i2 = `i1' + `lnum'
			}
			else	local i2 = `i0' + `lnum' + 1
			global Tnarchex $Tnarchex + `b'[1,`i1'] *	    /*
			*/  abs(					    /*
			*/	cond(l``i''.$Te >= ., $Tabse_0,	l``i''.$Te) /*
			*/      - `b'[1,`i2']				    /*
			*/   )^2
			local i = `i' + 1
		}
		global Tnarchex : subinstr global Tnarchex "`b'" "\`b'", all

		local init = cond("`archb0'"=="", .05, .005)
		if "`narchk'" == "" {
			mat `T' = J(1, 2*`lnum', `init')
		}
		else	mat `T' = J(1, `lnum'+1, `init')
		mat `b0' = nullmat(`b0') , `T'

		tsunab naterms : l(`narch').$Te		/* var doesn't matter */
		if "`narchk'" == "" {
			local neqn (NARCH:  = `naterms' `naterms', nocons)
		}
		else	local neqn (NARCH:  = `naterms' $Te, nocons)

					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "`narch'" ARCH narch
		if "`narchk'" == "" {
			AddStrip colnams : "`colnams'" "`narch'" ARCH narch_k
		}
		else	AddStrip colnams : "`colnams'" "0" ARCH narch_k
	}

					/* asymmetric terms and equation*/
					/* b(|e_(t-i)| + a*e_(t-i)	*/
					/* priming values are plug-ins	*/
	if "$Taarch" != "" {
		tempname b
		capture local i0 = colsof(`b0')
		if _rc { local i0 0 }

		local lnum : word count $Taarch
		tokenize $Taarch
		local i 1
		global Taarchex update $Tsigma2 = $Tsigma2 
		while "``i''" != "" {
			local i1 = `i0' + `i'
			local i2 = `i1' + `lnum'
			global Taarchex $Taarchex + `b'[1,`i1'] *	/*
			*/  (						/*
			*/	cond(l``i''.$Te >= .,			/*
			*/		$Tabse_0 , 			/*
			*/		abs(l``i''.$Te)			/*
			*/	) + 					/*
			*/	`b'[1,`i2'] *	 			/*
			*/	cond(l``i''.$Te >= ., 0, l``i''.$Te)	/*
			*/   )^2
			local i = `i' + 1
		}
		global Taarchex : subinstr global Taarchex "`b'" "\`b'", all

		mat `T' = J(1, 2*`lnum', cond("`archb0'"=="", .05, .005))
		mat `b0' = nullmat(`b0') , `T'

		local aaeqn (AARCH:  = l(`aarch').$Te l(`aarch').$Tu, nocons)
							/* vars don't matter */

					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "`aarch'" ARCH aarch
		AddStrip colnams : "`colnams'" "`aarch'" ARCH aarch_e
	}
					/* Globals for power ARCH terms */

	if "$Tparch$Ttparch$Taparch$Tnparch$Tpgarch" != "" {
		tempname aparchb power 
		global Tpower `power'

		tempvar sig_pow 
		global Tsig_pow `sig_pow'
		qui gen double $Tsig_pow = . in 1

					/* Look ahead for Power terms */
		if "$Tparch$Ttparch$Tpgarch" != "" {
			local powrest "+ $Ttvar"
		}
	}


					/* APARCH terms and equation	*/
					/* (b(|e_(t-i)| + a*e_(t-i))^c	*/
	if "$Taparch" != "" {		/* priming values are plugins	*/
		tempname b
		capture local i0 = colsof(`b0')
		if _rc { local i0 0 }

		local lnum : word count $Taparch
		tokenize $Taparch
		local i 1
		global Taparchx update $Tsig_pow = $Tsigma2 `powrest'
		local powrest
		while "``i''" != "" {
			local i1 = `i0' + `i'
			local i2 = `i1' + `lnum'
			global Taparchx $Taparchx + `b'[1,`i1'] *	/*
			*/  (						/*
			*/	cond(l``i''.$Te >= .,			/*
			*/		$Tabse_0 ,			/*
			*/		abs(l``i''.$Te)			/*
			*/	) + 					/*
			*/	`b'[1,`i2'] * 				/*
			*/	cond(l``i''.$Te >= ., 			/*
			*/		$Tabse_0 ,			/*
			*/		l``i''.$Te			/*
			*/	)					/*
			*/   )^$Tpower
			local i = `i' + 1
		}
		global Taparchx : subinstr global Taparchx "`b'" "\`b'", all

		mat `T' = J(1, 2*`lnum', cond("`archb0'"=="", .05, .005))
		mat `b0' = nullmat(`b0') , `T'

		local apcheqn (APARCH:  = l(`aparch').$Te 		/*
			*/ l(`aparch').$Tu, nocons)	/* vars don't matter */

					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "`aparch'" ARCH aparch
		AddStrip colnams : "`colnams'" "`aparch'" ARCH aparch_e
	}

					/* NPARCH terms and equation	*/
					/* (b(|e_(t-i)| - k)^c	*/
	if "$Tnparch" != "" {		/* priming values are plug-ins */
		tempname b
		capture local i0 = colsof(`b0')
		if _rc { local i0 0 }

		local lnum : word count $Tnparch
		tokenize $Tnparch
		local i 1
		if "$Taparch" == "" {
			global Tnparchx update $Tsig_pow = $Tsigma2 `powrest'
		}
		else	global Tnparchx update $Tsig_pow = $Tsig_pow `powrest'
		while "``i''" != "" {
			local i1 = `i0' + `i'
			if "`nparchk'" == "" {
				local i2 = `i1' + `lnum'
			}
			else	local i2 = `i0' + `lnum' + 1
			global Tnparchx $Tnparchx + `b'[1,`i1'] *	/*
			*/  abs(					/*
			*/	cond(l``i''.$Te >= .,			/*
			*/		$Tabse_0 , 			/*
			*/		l``i''.$Te			/*
			*/	) - `b'[1,`i2']				/*
			*/   )^$Tpower
			local i = `i' + 1
		}
		global Tnparchx : subinstr global Tnparchx "`b'" "\`b'", all

		local init = cond("`archb0'"=="", .05, .005)
		if "`nparchk'" == "" {
			mat `T' = J(1, 2*`lnum', `init')
		}
		else	mat `T' = J(1, `lnum'+1, `init')
		mat `b0' = nullmat(`b0') , `T'

		if "`nparchk'" == "" {
			local npcheqn (NPARCH:  = l(`nparch').$Te 	/*
				*/ l(`nparch').$Tu, nocons)	/* any vars */
		}
		else {
			local npcheqn (NPARCH:  = l(`nparch').$Te)
		}

					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "`nparch'" ARCH nparch
		if "`nparchk'" == "" {
			AddStrip colnams : "`colnams'" "`nparch'" ARCH nparch_k
		}
		else	AddStrip colnams : "`colnams'" 0 ARCH nparch_k
	}

					/* EARCH terms (could use Monfort) */
					/* a*abs(u/sigma) + b*(u/sigma) */
					/*    a*abs(z)    +   b*z	*/
	if "$Tearch" != "" {
		tempvar z absz tearch tearcha
		global Tz `z'
		global Tabsz `absz'
		global Ttearch `tearch'
		global Ttearcha `tearcha'
		qui gen double $Tz = . in 1
		qui gen double $Tabsz = . in 1
		qui gen double $Ttearch = . in 1
		qui gen double $Ttearcha = . in 1
		global Tnormadj = sqrt(2 / _pi)

		local lnum : word count `earch'
		mat `T' = J(1, 2*`lnum', .0)
		mat `b0' = nullmat(`b0') , `T'

		local eaeqn1 (EARCH:  = l(`earch').$Tz, nocons)
		local eaeqn2 (EARCHa:  = l(`earch').$Tabsz, nocons)

					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "`earch'" ARCH earch
		AddStrip colnams : "`colnams'" "`earch'" ARCH earch_a
	}
	else {
		global Tdoearch "*"
		global Ttearch 0
		global Ttearcha 0
	}

					/* EGARCH terms (could use Monfort) */
					/*   a*ln(sigma^2)		*/
	if "$Tegarch" != "" {
		tempvar lnsig2 tegarch
		global Tlnsig2 `lnsig2'
		global Ttegarch `tegarch'
		qui gen double $Tlnsig2 = . in 1
		qui gen double $Ttegarch = . in 1

		local lnum : word count `egarch'
		mat `T' = J(1, `lnum', .0)
		mat `b0' = nullmat(`b0') , `T'

		local egeqn (EGARCH:  = l(`egarch').$Tlnsig2, nocons)

					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "`egarch'" ARCH egarch

	}
	else {
		global Tdoegrch "*"
		global Ttegarch 0
	}

	if "$Tearch$Tegarch" == "" { 
		global Tdoeaeg "*" 
	}
	else if "$Tparch$Tpgarch$Ttparch" == "" { qui replace $Te2 = ln($Te2) }
				/* prep u^2 for remaining initial comps */

				/* PGARCH, TPARCH, ABPARCH terms */

	if "$Ttparch" != "" {
		tempvar e_tpow
		global Te_tpow `e_tpow'
		qui gen double $Te_tpow = ($Te > 0)*abs($Te)^`pow0'
			*/ cond($Te > 0, abs($Te)^`pow0', 0)
		global Ttpowex  /*
			*/ "update $Te_tpow = ($Te > 0)*abs($Te)^$Tpower"
	}

	if "$Tparch" == "" { global Tdoabpow "*" }

	if "$Tparch$Tpgarch$Ttparch" != "" {
		tempvar e_abpow
		global Te_abpow `e_abpow'
		qui gen double $Te_abpow = $Te2^(`pow0'/2)
		if "$Tparch" != ""  {
			global Tabpowex "update $Te_abpow = abs($Te)^$Tpower"
		}

		if "$Tparch" != "" { local abterms "l($Tparch).$Te_abpow" }
		if "$Ttparch" != "" { local taterms "l($Ttparch).$Te_tpow" }
		if "$Tpgarch" != "" { local gaterms "l($Tpgarch).$Tsig_pow" }

		local docons = /*
*/ "`archcon'$Tarch$Tgarch$Ttarch$Tsaarch$Tabarch$Tatarch$Tearch$Tegarch$Tsdgarch"=="" 

		if "`archb0'" == "" {
			/* Get residuals from AR representation of errors */
			MinLag minlag : "$Tparch" "$Tpgarch" "$Ttparch" 
			if "$Tparch$Ttparch" != "" {
				numlist "$Tparch $Ttparch", sort
				MaxLagS maxlag : 2 "`r(numlist)'" "$Tpgarch"
			}
			else	MaxLagS maxlag : 1 "$Tpgarch"

			capture Monfort $Tsig_pow : $Te_abpow  /*
				*/ `minlag' `maxlag' `interva' `touse'

			/* Get b0 estimates of ABPARCH and PGARCH parameters */

			capture regress $Te_abpow `abterms' `taterms'  /*
				*/ `gaterms' if `touse'
			if !_rc {
				mat `T' = e(b)
				if !`docons' { 
					mat `T' = `T'[1,1..colsof(`T')-1] 
				}


if "$Tpgarch" != "" {			/* <=========== */
			/*  compute parch and pgarch params from regression */
	local nar : word count $Tparch $Ttparch
	local gar : word count $Tpgarch
	tokenize $Tparch
	local i 1 
	while "``i''" != "" {
		local done 0
		local j 1
		while !`done' & `j' <= `gar' {
			local glag : word `j' of $Tpgarch
			if ``i'' == `glag' {
				local gj = `nar' + `j'
				mat `T'[1,`i'] = `T'[1,`i'] + `T'[1,`gj']
				mat `T'[1,`gj'] =  -`T'[1,`gj']
				local done 1
			}
			local j = `j' + 1
		}
		local i = `i' + 1
	}
}					/* ===========> */

			mat `b0' = nullmat(`b0') , `T'
			}
			else	local archb0b "archb0"
		}
		if "`archb0'`archb0b'" != "" {
			local ct : word count $Tparch $Ttparch $Tpgarch
			mat `T' = J(1, `ct', 0)
			mat `b0' = nullmat(`b0') , `T'
			if `docons' {
				sum $Te_abpow, meanonly, if `touse'
				mat `b0' = `b0', r(mean)
			}
		}


					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "$Tparch" ARCH parch
		AddStrip colnams : "`colnams'" "$Ttparch" ARCH tparch
		AddStrip colnams : "`colnams'" "$Tpgarch" ARCH pgarch
		if `docons' {
			local colnams `colnams' ARCH:_cons 
			local archcon "nocons"
		}
		else	local mycons "nocons" 

					/* ML equation */
		local powaeqn  ( PARCH:  `yprefix' = `abterms' `taterms'  /*
			*/ `gaterms' , `mycons' )
		local yprefix

					/* S^p updating in arch_dr */
		if "$Taparch$Tnparch" == "" {
			global Taparchx update $Tsig_pow = $Tsigma2 + $Ttvar
		}
		local abterms
		local taterms
		local gaterms
			
				/* prep u^2 for remaining initial comps */
		qui replace $Te2 = $Te2^(1/`pow0')
		if "$Tearch$Tegarch" != "" { qui replace $Te2 = ln($Te2) }
	}
	else if "$Taparch$Tnparch" == "" {

⌨️ 快捷键说明

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