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

📄 arch.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 4 页
字号:
	}
	c_local `numlfix' `fixed'
end


program define PrsArch0
	syntax [, Xb XB0 XB0wt XBWt Zero * ]

	global Tarch0 = trim("`xb0' `xb0wt' `xb' `xbwt' `zero' `options'")
	local ct : word count $Tarch0

	if `ct' == 0 {
		global Tarch0 xb
		exit
	}

	if `ct' > 1 {
		di in red "arch0() may contain one only from:  "
		di in red "xb, xb0, xb0wt xb, xbwt, zero, #"
		exit 198
	}

	if "`zero'" != "" { 
		scalar $Tsig2_0 = 0 
		exit
	}

	capture confirm number $Tarch0 
	if !_rc {
		scalar $Tsig2_0 = $Tarch0
		exit
	}

	if "`options'" != "" {
		di in red "invalid arch0($Tarch0)"
		exit 198
	}

	/* otherwise, just return the specified option */
end


program define PrsArma0
	syntax [, P Q PQ QP Zero 0 * ]

				/* Dont include `*' in next line */
	global Tarma0 = trim("`p' `q' `pq' `qp' `zero' `0'")

	global Tarma0v = 0 
	
	if "$Tarma0" == "" {
		global Tarma0 p
		exit
	}

	if "$Tarma0" == "p" {
		local end : word count $Tar
		if `end' != 0 { global Tskipobs : word `end' of $Tar }
		exit 
	}

	if "$Tarma0" == "q" {
		local end : word count $Tma
		if `end' != 0 { global Tskipobs : word `end' of $Tma }
		exit 
	}

	if "$Tarma0" == "pq" | "$Tarma0" == "qp" {
		local end : word count $Tar
		if `end' != 0 { global Tskipobs : word `end' of $Tar }

		local end : word count $Tma
		if `end' != 0 { local skipma : word `end' of $Tma }

		global Tskipobs = 0$Tskipobs + 0`skipma'
		if $Tskipobs == 0 { global Tskipobs }
		exit 
	}

	if "$Tarma0" == "zero" | "$Tarma0" == "0" {
		exit
	}

	if real("`options'") < . {
		global Tarma0v = real("`options'")
		exit
	}
	
	di in red "arma0() may contain one only from:  p, q, pq, qp, zero, 0"
	exit 198

end


program define DropDup	/* Remove duplicate tokens from a sorted list */
	args	    listfix	/*  a macro name to hold the the fixed list
		*/  colon	/*  :
		*/  list	/*  original list */

	tokenize `list'
	local prev `1'
	local i 2
	while "``i''" != "" {
		if "``i''" == "`prev'" {
			local ``i''
		}
		else    local prev ``i''

		local i = `i' + 1
	}

	c_local `listfix' `*'
end

program define AddStrip 
	args	    stripe	/* macro to contain full matrix names
		*/  colon	/* :
		*/  stripe0	/* current contents of strip
		*/  laglist	/* list of lags
		*/  eqname	/* equation name for this part of stripe
		*/  varname	/* variable name for this part of stripe */

	tokenize `laglist'
	local i 1
	while "``i''" != "" {
		local part `part' `eqname':L``i''.`varname'
		local i = `i' + 1
	}

	c_local `stripe' `stripe0' `part'
end

program define FixARMA
	args	    b

	tempname bsum
	scalar `bsum' = 0

						/* AR terms */
	local nar : word count $Tar
	local i 1
	while `i' <=  `nar' {
		scalar `bsum' = `bsum' + `b'[1, `i']
		local i = `i' + 1
	}

	if abs(`bsum') > .95 {
		mat `b'[1,1] = (.95 / abs(`bsum')) * `b'[1,1..`nar']
	}

						/* MA terms */
	local nma : word count $Tma
	local narma = `nma' + `nar'
	local i = `nar' + 1
	while `i' <=  `narma' {
		if abs(`b'[1, `i']) > 0.95 {
			mat `b'[1, `i'] = .95 * `b'[1, `i'] / abs(`b'[1, `i'])
		}
		local i = `i' + 1
	}
end

program define FixARCH		/* only for arch/garch terms */
	args b nocons

	tempname bsum
	scalar `bsum' = 0

	local cols = colsof(`b') - ("`nocons'" == "")
	local i 1
	while `i' <= `cols' {
		if `b'[1,`i'] < .01 { mat `b'[1,`i'] = .01 }
		scalar `bsum' = `bsum' + `b'[1,`i']
		local i = `i' + 1
	}

	if "`nocons'" == "" {
		if `b'[1,colsof(`b')] <= 0 {
			mat `b'[1,colsof(`b')] = .01
		}
	}

	if `bsum' > .95 {
		mat `b'[1,1] = (.95 / `bsum') * `b'[1,1..`cols']
	}

end


program define EstType 
	args	    ml_prog	/*  likelihood evaluation program name
		*/  title	/*  primary title for the model
		*/  title2	/*  secondary title for the model
		*/  colon	/*  :					*/

	c_local `ml_prog' arch_dr

	if $Tarchany {
		local ltitle "ARCH family regression"
	}
	else	local ltitle "Time-series regression"

	if "$Tar$Tma" != "" & "$Tmhet" != "" {
local ltitle "`ltitle'  -- ARMA disturbances and mult. heteroskedasticity"
	}
	else if "$Tar" != "" & "$Tma" != "" { 
		local ltitle "`ltitle' -- ARMA disturbances" 
	}
	else if "$Tar" != "" { 
		local ltitle "`ltitle' -- AR disturbances" 
	}
	else if "$Tma" != "" { 
		local ltitle "`ltitle' -- MA disturbances" 
	}
	else if "$Tmhet" != "" {
		local ltitle "`ltitle' -- multiplicative heteroskedasticity"
	}

	c_local `title' `ltitle'
end


program define MinLag		/* minlag : numlist1 numlist2 ... numlistN */
	args minlag colon

	mac shift 2
	local i 1

	numlist "`*'", sort
	local nlist `r(numlist)'
	gettoken minval : nlist

	c_local `minlag' `minval'
end

program define MaxLag		/* maxlag : numlist1 numlist2 ... numlistN */
	args maxlag colon

	mac shift 2
	
	numlist "`*'", sort

	local lastel : word count `r(numlist)'
	local lastval : word `lastel' of `r(numlist)'

	c_local `maxlag' `lastval'
end

program define MaxLagS		/* sumlag : N "nlist1" "nlist2" ... "nlistN" */
	args maxlag colon k_list

	mac shift 3
	local maxsum 0

	local i 1
	while `i' <= `k_list' {
		if "``i''" != "" {
			local lastel : word count `i'
			local last : word `lastel' of `i'
			local maxsum = `maxsum' + `last'
		}
		local i = `i' + 1
	}

	c_local `maxlag' `maxsum'
end


/* Obtain whitened residuals of a series from an "infinite" AR regression
 * regression.  Used to get a disturbance estimate that can be used for
 * the MA component of a regression; a'la Monfort & Gourieux TS p 188 
*/

program define Monfort
	args	    u_var	/* variable to hold whitened resids
		*/  colon	/* :
		*/  e_var	/* variable with ARMA resids
		*/  minlag	/* minimum lag 
		*/  maxlag	/* smallest maximum lag value	
		*/  inter	/* true interval of time variable 
		*/  touse	/* touse variable */

	/* search for a reasonble lag for infinite AR representation */
	/* a space problem here since k doubles are created in regress. */

	tempvar touse2
	qui gen byte `touse2' = . in 1

	local vir 1
	local done 0
	local k = 30				/* would prefer 40 */
	while ! `done' & `k' > 0 {
		if `k' > 10 {
			local usemin = min(`minlag', `inter')
		}
		else    local usemin `minlag'

		local usemax = max(`maxlag', `usemin'+`k'*`inter')

		qui replace `touse2' = `touse'
		capture  markout `touse2' `e_var' /*
			*/ l(`usemin'(`inter')`usemax').`e_var'
		if !_rc {
			qui count if `touse2'
			if r(N) > 2*`k' { local done 1 }
		}
		else if `vir' {
			di in gr "(note:  insufficient memory or "	/*
				*/ "observations to estimate usual"
			di in gr "starting values [1])"
			local vir 0
		}
		local k = `k' - 5

	}

		/* Obtain near white u's from "infinite" AR regress */

	while `usemax' > `usemin' {
		capture regress `e_var' l(`usemin'(`inter')`usemax').`e_var' /* 
			*/ if `touse'
		local hold_rc = _rc
		if !`hold_rc' { 
			capture drop `u_var'
			qui predict double `u_var' if `touse', res
			exit
		}

		if `vir' {
			di in gr "(note:  insufficient memory or "	/*
				*/ "observations to estimate usual"
			di in gr "starting values [2])"
			local vir 0
		}
		local usemax = `usemax' - 1
	}
	
	capture drop `u_var'
	qui gen double `u_var' = . in 1

	if `hold_rc' == 2000 { 
		di in red "insufficient observations"
		exit 2000
	}
	di in red "insufficient memory or observations to estimate " /*
		*/ "starting values"
	exit `hold_rc'
end


program define ErrCheck
	if _rc == 111 | _rc == 2000 {
		di in gr "insufficient observations"
		exit _rc
	}

	if _rc {
		error _rc
		exit
	}
end

	


exit

partial list of globals set and used by arch_dr:
	Tar         numlist of AR terms in ARMA disturbances model
	Tma         numlist of MA terms in ARMA disturbances model
	Tarch       numlist of ARCH terms in ARCH variance model
	Tgarch      numlist of GARCH terms in ARCH variance model
	Tarchm      numlist of ARCH-in-mean terms in model
	Ttarch      numlist of threshold ARCH terms in ARCH variance model
	Tsaarch     numlist of simple asymmetric ARCH terms in ARCH model
	Taarch      numlist of asymmetric ARCH terms in ARCH variance model
	Tnarch      numlist of nonlinear NARCH terms in ARCH variance model
	Taparch     numlist of asym power APARCH terms in ARCH variance model
	Tpgarch     numlist of PGARCH terms in ARCH variance model (s^p)
	Tearch      numlist of EARCH terms in ARCH variance model a*z + b*|z|
	Tegarch     numlist of EGARCH terms in ARCH variance model (ln(s^2))
	Taarchex    evaluation expression for arch asymmetric terms
	Taarchb     global name to hold b for aarch terms
	Tnarchex    evaluation expression for narch terms
	Taparchx    evaluation expression for arch APARCH expression
	Tnparchx    evaluation expression for arch NPARCH expression
	Taparchb    global name to hold b for APARCH terms
	Tpower      global to hold scalar name for APARCH/NPARCH power
	Tarchany    1 if any Arch/Garch components specified 0 otherwise
	Tdopowi     1 if any power terms, 0 otherwise
	Tu          tempvar for regression disturbances (may be ARMA)
	Te          tempvar for white noise disturbances (MA and ARCH inputs)
	Te2         tempvar for ARCH white noise disturbances^2 
	Tsigma2     tempvar for ARCH/GARCH sigma2
	Te_tarch    tempvar for TARCH thresholded disturbances^2
	Tabse       tempvar for ABARCH variable |e|
	Tz          tempvar for Te / sqrt(Tsigma2)
	Tabsz       tempvar for abs(Tz)
	Ttearch     tempvar for temporary storage of a EARCH component
	Ttearcha    tempvar for temporary storage of an EARCH component
	Ttegarch    tempvar for temporary storage of an EGARCH component
	Ttpgarch    tempvar for temporary storage of an PGARCH component
	Ttarchm     tempvar for temporary storage of an ARCHM score
	Ttarchme    tempvar for temporary storage of an ARCHM expression var
	Tlnsig2     tempvar for ln(sigma^2)
	Tsig_pow    tempvar for sigma^p  -- power arch/garch
	Thasxb      1 ==> there is an B vector for the model mean
	Tmhet       has multiplicative heteroskedasticity terms
	Tarchmex    expression used to modify each arch-in-mean term
	Tsig2_0	    scalar to store priming values for sigma^2
	Tabse_0	    scalar to store priming values for |e|
	Ts2_mayb    holds Tsig2_0 for possible adoption at iteration change
	Tnormadj    holds the E(|u|) adjustment for EARCH terms
	Ttimevar    contains the name of the time variable 
	Ttimemin    the value of time for the first observation in the sample
	Tadjt       T-1 for computing weighted sigma_0^2 and e_0^2
	Tarch0      conditioning for ARCH:  xb0, xb, xbwt, zero, ...
	Tarma0      conditioning for ARCH:  xb0, xb, xbwt, zero, ...
	Tskipobs    number of observations at the beginning of the 
			sample to skip for conditioning
	Ttouse2     sample over which likelihood is actually calculated
			excludes p, q, or p+q startup obs for arma for
			every sample break.
	Tarma0v	   presample value of e(t) to be used in ARMA terms
	TXbeq      name of Xb equation
	
	Tdoarch     "*" if not doing ARCH/GARCH/TARCH/ABARCH/AARCH terms
	Tdoarma     "*" if not doing AR or MA
	Tdotarch    "*" if not doing TARCH
	Tdoarchm    "*" if not doing ARCHM
	Tdarchme    "*" if not doing ARCHM expression
	Tdoearch    "*" if not doing EARCH
	Tdoegrch    "*" if not doing EGARCH
	Tdoeaeg     "*" if doing neither EARCH nor EGARCH
	Tdopgrch    "*" if not doing PGARCH
	Tdopow      "*" if not doing parch, tparch, or pgarch
	Tdopowa     "*" if not doing any power ARCH


Notes
-----

e(sample) is the full count of observations, including any that are
        conditioned on, but who did not contribute to the likelihood.  I think
        this is right.

+
-
o  monfort starting values for egarch

arch:    L(1)(arch*e^2)
garch:   L(1)(garch*S^2)
aparch:  L(1)(aparch*(|e| + aparch_e*e)^power)
nparchk: L(1)(nparch*(e - k)^power)

⌨️ 快捷键说明

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