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

📄 arch.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 4 页
字号:
		global Tdopow  "*"
		global Tdopowa "*"
	}
	else	global Tdopow "*"

				/* ABARCH, ATARCH, SDGARCH */

	if "$Tabarch$Tatarch$Tsdgarch" != "" {

		tempvar abse
		global Tabse `abse'
		qui gen double $Tabse = abs($Te)
		if "$Tabarch" != "" {
			global Tabe_upd update $Tabse = abs($Te)
		}

		if "$Tatarch" != "" {
			tempvar tabse
			global Ttabse `tabse'
			qui gen double $Ttabse = abs($Te) * ($Te > 0)
			global Ttae_upd update $Ttabse = abs($Te)*($Te > 0)
		}

		tempvar sig
		global Tsig `sig'
		if "$Tsdgarch" != "" {
			qui gen double $Tsig = . in 1
			global Tsig_upd update $Tsig = sqrt($Tsigma2)
		}

		global Tsd_scr  /*
			*/ score $Tsig = \`b', eq("SDARCH") missval(\`sig_0')
		global Tsd_updt update $Tsigma2 = $Tsigma2 + $Tsig^2

		if "$Tabarch" != "" { local abterms "l($Tabarch).$Tabse" }
		if "$Tatarch" != "" { local atterms "l($Tatarch).$Ttabse" }
		if "$Tsdgarch" != "" { local sdterms "l($Tsdgarch).$Tsig" }

		local docons = "`archcon'$Tarch$Tgarch$Ttarch$Tsaarch"=="" 
		if "`archb0'" == "" {
			/* Get residuals from AR representation of errors */
			MinLag minlag : "$Tabarch" "$Tsdgarch" "$Tatarch" 
			if "$Tabarch$Tatarch" != "" {
				numlist "$Tabarch $Tatarch", sort
				MaxLagS maxlag : 2 "`r(numlist)'" "$Tsdgarch"
			}
			else	MaxLagS maxlag : 1 "$Tsdgarch"

			capture Monfort $Tsig : $Tabse `minlag' `maxlag'  /*
				*/ `interva' `touse'

			/* Get b0 estimates of ABARCH and SDGARCH parameters */

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


if "$Tsdgarch" != "" {			/* <=========== */
			/*  compute parch and pgarch params from regression */
	local nar : word count $Tabarch $Tatarch
	local gar : word count $Tsdgarch
	tokenize $Tsdgarch
	local i 1 
	while "``i''" != "" {
		local done 0
		local j 1
		while !`done' & `j' <= `gar' {
			local glag : word `j' of $Tsdgarch
			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 $Tabarch $Tatarch $Tsdgarch
			mat `T' = J(1, `ct', 0)
			mat `b0' = nullmat(`b0') , `T'
			if `docons' {
				sum $Te2, meanonly, if `touse'
				mat `b0' = `b0', sqrt(r(mean))
			}
		}


					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "$Tabarch" ARCH abarch
		AddStrip colnams : "`colnams'" "$Tatarch" ARCH atarch
		AddStrip colnams : "`colnams'" "$Tsdgarch" ARCH sdgarch
		if `docons' {
			local colnams `colnams' ARCH:_cons 
			local archcon "nocons"
			local mycons
		}
		else	local mycons "nocons" 

					/* ML equation */
		local sdeqn  ( SDARCH:  `yprefix' = 		/*
			*/ `abterms' `atterms' `sdterms', `mycons' )
		local yprefix

		local abterms
		local atterms
		local sdterms
	}
				/* ARCH, GARCH, TARCH, SAARCH, terms */

	if "$Ttarch" != "" {
		tempvar e_tarch
		global Te_tarch `e_tarch'
		qui gen double $Te_tarch = ($Te > 0)*$Te2
	}
	else	global Tdotarch "*"


	if "$Tarch$Tgarch$Ttarch$Tsaarch" != "" {

		if "$Tarch"  != "" { local acterms "l($Tarch).$Te2" }
		if "$Tgarch" != "" { local gaterms "l($Tgarch).$Tsigma2" }
		if "$Ttarch" != "" { local taterms "l($Ttarch).$Te_tarch" }
		if "$Tsaarch" != "" { local aaterms "l($Tsaarch).$Te" }

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

			capture Monfort $Tsigma2 : $Te2   /*
				*/ `minlag' `maxlag' `interva' `touse'

			/* Get b0 estimates of ARCH and GARCH parameters */

			capture regress $Te2 `acterms' `abterms' `atterms' /*
				*/ `taterms' `aaterms' `gaterms'	   /*
				*/ if `touse'
			if !_rc {
				mat `T' = e(b)
				if "`archcon'" != "" { 
					mat `T' = `T'[1, 1..colsof(`T')-1]
				}

if "$Tgarch" != "" {			/* <=========== */
			/*  compute arch and garch params from regression */
	local nar : word count $Tarch $Ttarch $Tsaarch 
	local gar : word count $Tgarch
	tokenize $Tarch
	local i 1 
	while "``i''" != "" {
		local done 0
		local j 1
		while !`done' & `j' <= `gar' {
			local glag : word `j' of `garch'
			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
	}
}					/* ===========> */

				if "$Ttarch$Tsaarch" ==  "" {
					FixARCH `T' `archcon'
				}
				mat `b0' = nullmat(`b0') , `T'
			}
			else	local archb0b "archb0"
		}
		if "`archb0'`archb0b'" != "" {
			local ct : word count $Tarch $Ttarch $Tsaarch $Tgarch
			mat `T' = J(1, `ct', 0)
			mat `b0' = nullmat(`b0') , `T'
			if "`archcon'" == "" {
				sum $Te2, meanonly, if `touse'
				mat `b0' = `b0', r(mean)
			}
			if "`archb0b'" == "" { 
				qui gen double $Tsigma2 = . in 1
			}
		}


					/* maintain name stripe */
		AddStrip colnams : "`colnams'" "$Tarch" ARCH arch
		AddStrip colnams : "`colnams'" "$Ttarch" ARCH tarch
		AddStrip colnams : "`colnams'" "$Tsaarch" ARCH saarch
		AddStrip colnams : "`colnams'" "$Tgarch" ARCH garch
		if "`archcon'" == "" { local colnams `colnams' ARCH:_cons }

					/* ML equation */
		if "$Tarch$Tgarch$Ttarch$Tsaarch" != "" | "`archcon'"=="" {
			local archeqn  ( ARCH:  `yprefix' = `acterms'	/*
				*/ `abterms' `atterms' `taterms' 	/*
				*/ `aaterms' `gaterms' , `archcon' )
			local yprefix
		}
	}
	else if $Tarchany & "`archcon'" == "" {
				/* Special case where we need a constant */
				/* Te2 already on proper scale for
				 * egarch, pgarch, if specified */
		local archeqn  ( ARCH:  `yprefix' = )
		local yprefix
		sum $Te2, meanonly, if `touse'
		mat `b0' = nullmat(`b0') , `r(mean)'
		local colnams `colnams' ARCH:_cons
		qui gen double $Tsigma2 = . in 1
	}
	else {
		qui gen double $Tsigma2 = . in 1
		global Tdoarch "*"
	}

				/* Power parameter */

	if "$Tparch$Ttparch$Taparch$Tnparch$Tpgarch" != "" {
		global Tdopowi 1
		local poweqn (POWER: = )
		mat `b0' = nullmat(`b0') , `pow0'
		AddStrip colnams : "`colnams'" 0 POWER power
	}
	else	global Tdopowi 0

				/* End starting values and matrix stripe */

				/* Maximize -- ML */

					/* Get title and method */
	EstType ml_prog title title2 :

					/* Handle constraints, if any */
	if "`constra'" != "" { 
						/* make constraints using 
						 * dummy matrices */
		tempname b V T a C 
						/* set full model */
		ml model rdu0 `ml_prog'		/*
			*/  `xbeqn' `ameaneq' `armaeqn' 		/*
			*/ `heteqn' `neqn' `aaeqn' `apcheqn' `npcheqn'	/*
			*/ `eaeqn1' `eaeqn2' `egeqn' `sdeqn'		/*
			*/ `powaeqn' `abcheqn' `archeqn' `poweqn'  /*
			*/ , `technique' `vce' missing nopreserve collinear

		mat `b' = $ML_b
		mat colnames `b' = `colnams'
		mat `V' = `b'' * `b'
		mat post `b' `V'
		capture mat makeCns `constra'
		if _rc {
			local rc = _rc
			di in red "Constraints invalid:"
			mat makeCns `constra'
			exit _rc
		}
		matcproc `T' `a' `C'
		global TT `T'			/* globals for LL evaluator */
		global Ta `a'
		global Tstripe : colfullnames $ML_b

						/* constrain b0 */
		if "`from'" != "" & "`archb0'`armab0'" == "" {
			_mkvec `b0', from(`from') first  /*
				*/ colnames(`colnams') error("from()")
		}
		mat `b0' = (`b0' - `a') * `T'			

  						/* for constrained model, 
						 * just feed ml first varnames
						 * of unconstrained model */
		tempname one
		qui gen byte `one' = . in 1
		mat `b' = $ML_b[1, 1..colsof(`b0')]
		local cnsvars : colnames `b'
		local cnsvars : subinstr local cnsvars "_cons" "`one'", all w

						/* give ML constrained model */
		local xbeqn "(`dep_m' = `cnsvars', nocons)"
		local ameaneq 
		local armaeqn
		local heteqn 
		local neqn 
		local aaeqn 
		local apcheqn 
		local npcheqn
		local eaeqn1 
		local eaeqn2 
		local egeqn 
		local sdeqn
		local powaeqn 
		local abcheqn 
		local archeqn 
		local poweqn 
	}
					/* Set initial values */
	if "`from'" != "" & "`archb0'`armab0'" == "" & "`constra'" == "" { 
		_mkvec `b0', from(`from') first  colnames(`colnams') /*
			*/ error("from()")
	}
	local from "`b0', copy" 


					/* Fit the model */
	if `nobs' < colsof(`b0') {
		di in gr "insufficient observations"
		exit 2000
	}
	capture noi ml model rdu0 `ml_prog' `xbeqn' `ameaneq' `armaeqn'	 /*
		*/ `heteqn' `neqn' `aaeqn' `apcheqn' `npcheqn'		 /*
		*/ `eaeqn1' `eaeqn2' `egeqn' `sdeqn'			 /*
		*/ `powaeqn' `abcheqn' `archeqn' `poweqn'		 /*
		*/ [`weight'`exp']  if `touse' ,			 /*
		*/ obs(`nobs') title(`title') `score' `robust'		 /*
		*/  missing maximize nooutput nopreserve collinear `log' /*
		*/  `technique' `vce' `difficult' gtolerance(`gtolera')	 /*
		*/  init(`from') search(off) `stdopts' `mlopts' `bracket'

	if _rc == 1400 & "`from'" == "`b0', copy" & "`archb0'`armab0'" == "" {
		di in gr "(note:  default initial values infeasible; "  /*
			*/ "starting ARCH/ARMA estimates from 0)"
		capture noi arch `0' from(armab0 archb0)
		if _rc == 198 { arch `0', from(armab0 archb0) }
		exit
	}
	else if _rc {
		exit _rc
	}

	if "`constra'" != "" {		/* put problem back in original space */
		mat `b' = get(_b) * `T'' + `a'
		mat `V' = `T' * e(V) * `T''
		mat post `b' `V' `C', noclear
	}

					/* Fix-up names on matrices */
	mat `b0' = e(b)
	local eqnames : coleq `b0'		/* for saved results */
	mat colnames `b0' = `colnams'
	mat repost _b=`b0', rename

					/* Model Chi	*/
	if "`ind_m'"  != "" { 
		tsrevar `dep_m', list
		qui test [`r(varlist)'] 
		local accum accum
	}
	if "`ar'`ma'" != "" { 
		qui test [ARMA], `accum' 
		local accum accum
	}
	if "`archm'" != "" { qui test [ARCHM], `accum' }
	if "`ar'`ma'`ind_m'`archm'" != "" { qui test }


					/* Saved results */
	est scalar p = e(p)
	est scalar df_m = r(df)
	est scalar chi2 = r(chi2)

					/* Saved results */

	sum `timevar' if `touse' , meanonly
	est scalar tmin = r(min)
	est scalar tmax = r(max)
	local fmt : format `timevar'
	est local tmins = trim(string(r(min), "`fmt'"))
	est local tmaxs = trim(string(r(max), "`fmt'"))

	est scalar archi  = $Tsig2_0
	if "$Tpower" != "" {est scalar power = $Tpower}
	est scalar N_gaps = `gaps'
	est scalar condobs = $Tskipobs

	est local cond `conditi'		/* flag that called by arima */
	est scalar archany = $Tarchany
	est local eqnames `eqnames'
	est local archm $Tarchm
	est local archmexp `archmex'
	est local ar $Tar
	est local ma $Tma
	est local mhet $Tmhet
	est local doarch $Tdoarch
	est local earch $Tearch
	est local egarch $Tegarch
	est local saarch $Tsaarch
	est local aarch $Taarch
	est local narch $Tnarch
	est local aparch $Taparch
	est local nparch $Tnparch
	est local saarch $Tsaarch
	est local parch $Tparch
	est local tparch $Ttparch
	est local abarch $Tabarch
	est local atarch $Tatarch
	est local tarch $Ttarch
	est local sdgarch $Tsdgarch
	est local pgarch $Tpgarch
	est local garch $Tgarch
	est local arch $Tarch
	est local title2 `title2'
	est local estat_cmd arch_estat
	est local predict arch_p
	est local tech `techniq'
	if "`e(vcetype)'" == "Robust" { 
		est local vcetype `e(vcetype2)' Semi-robust 
	}
	if "`e(vce)'" == "oim" {
		est local vcetype "OIM"
	}

	est local cmd "arch"

					/* Results */

	Display , `coef' `head' level(`level')
	mac drop T*			
end


program define Display
	syntax [, Level(cilevel) noCOEF noHEAD ]

	if "`head'" == "" { _tsheadr }
	if "`coef'" == "" { estimates display , level(`level') }
end


program define Check0	/* Remove 0's from lag numlists */ /* not used */
	args	    numlfix	/* local macro for numlist with " 0 " removed 
		*/  colon	/*  :
		*/  numl	/* original numlist
		*/  note	/* name to go on note of " 0 " found */

	local fixed : subinstr local numl "0" "", all word count(local ct)

	if `ct' > 0 {
		di in gr "note: 0 lag in `note' ignored"

⌨️ 快捷键说明

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