📄 arch.ado
字号:
*! version 6.0.21 04apr2005
program define arch, eclass
version 6.0, missing
/* limits, etc. */
local mnonlin 50 /* sarch narch ... terms */
local gtol .05 /* gradient tolerance */
local pow0 2.0
if replay() {
if "`e(cmd)'" != "arch" {
noi di in red "results of arch not found"
exit 301
}
Display `0'
exit
}
syntax [varlist(ts)] [if] [in] [iw] [, /*
*/ AArch(numlist int ascend >0 max=`mnonlin') /*
*/ ABarch(numlist int ascend >0) /*
*/ AParch(numlist int ascend >0 max=`mnonlin') /*
*/ AR(numlist int ascend >0) ARCH(numlist int ascend >0) /*
*/ ARIMA(numlist int min=3 max=3 >-1) /*
*/ ARCH0(string) /*
*/ ARCHM ARCHMLags(numlist int ascend >= 0) ARCHMExp(string) /*
*/ ARMA0(string) /*
*/ ATarch(numlist int ascend >0) /*
*/ BHHH BHHHQ BFGS /*
*/ BHHHBfgs(numlist min=2 max=2 integer >=0 <99999) /*
*/ BHHHDfp(numlist min=2 max=2 integer >=0 <99999) /*
*/ noBRacket /*
*/ CONDition CONDObs(integer 0) noCOEF noConstant /*
*/ Constraints(string) /*
*/ DETail DFP noDIFficult /*
*/ EArch(numlist int ascend >0) EGarch(numlist int ascend >0) /*
*/ FROM(string) GTOLerance(real `gtol') /*
*/ Garch(numlist int ascend >0) noHEAD /*
*/ * ]
local varlst0 `varlist'
local if0 `"`if'"'
local in0 `in'
local weight0 `weight'
local exp0 `"`exp'"'
local real0 `"`0'"'
local 0 `", `options'"'
syntax [, /*
*/ HESsian /*
*/ Het(varlist ts numeric) /*
*/ Interval(integer 1) /*
*/ Level(cilevel) noLOg /*
*/ MA(numlist int ascend >0) /*
*/ MLOpts(string) /*
*/ NATIVE /*
*/ NArch(numlist int ascend >0 max=`mnonlin') /*
*/ NARCHK(numlist int ascend >0 max=`mnonlin') /*
*/ NParch(numlist int ascend >0 max=`mnonlin') /*
*/ NPARCHK(numlist int ascend >0 max=`mnonlin') /*
*/ NR /*
*/ OPG /*
*/ Parch(numlist int ascend >0) /*
*/ PGarch(numlist int ascend >0) /*
*/ Robust SCore(passthru) /*
*/ SAArch(numlist int ascend >0) /*
*/ SDgarch(numlist int ascend >0) /*
*/ SAVEspace /*
*/ TArch(numlist int ascend >0) /*
*/ TParch(numlist int ascend >0) /*
*/ TECHnique(string) /*
*/ VCE(string) /*
*/ * ]
local varlist `varlst0'
local if `"`if0'"'
local in `in0'
local weight `"`weight0'"'
local exp `"`exp0'"'
local 0 `"`real0'"'
local varlst0
local if0
local in0
local weight0
local exp0
local real0
/* Handle arima() option */
if "`arima'" != "" {
if "`ar'`ma'" != "" {
di in red "ar() and ma() not allowed with arima()"
exit 198
}
tokenize `arima'
local p `1'
local d `2'
local q `3'
tokenize `varlist'
local varlist
local i 1
while "``i''" != "" {
local varlist `varlist' D`d'.``i''
local i = `i' + 1
}
if `p' != 0 {
numlist "1/`p'"
local ar `r(numlist)'
}
if `q' != 0 {
numlist "1/`q'"
local ma `r(numlist)'
}
}
_ts timevar panvar, sort panel
qui tsset
mac drop T*
global Tarchany = "`arch'`abarch'`atarch'`parch'`aparch'`nparch'`nparchk'`tarch'`tparch'`saarch'`aarch'`narch'`narchk'`earch'" != ""
/* Other syntax errors */
if "`earch'`egarch'" != "" & /*
*/ "`parch'`aparch'`nparch'`nparchk'`tparch'`pgarch'" != "" {
di in red "parch(), aparch(), nparch(), nparchk(), "/*
*/ "tparch(), or pgarch()"
di in red "may not be specified with earch() or egarch()"
exit 198
}
if "`archm'`archmlags'" != "" & !$Tarchany {
di in red "options archm and archmlags() require that " /*
*/ "some form of arch terms "
di in red "be specified in the model"
exit 198
}
if "`aarch'" != "" & "`tarch'`arch'" != "" {
di in red "aarch() may not be specified with arch() or tarch()"
di in red "the resulting terms would be collinear"
exit 198
}
if "`nparch'`nparchk'`narch'`narchk'" != "" & "`saarch'`arch'" != "" {
di in red "nparch(), narch() or narchk() may not be " /*
*/ "specified with arch() or saarch()"
di in red "the resulting terms would be collinear"
exit 198
}
if ("`nparch'"!="") + ("`narch'"!="") + ("`narchk'"!="") + /*
*/ ("`nparchk'"!="") > 1 {
di in red "nparch(), nparchk() narch(), and narchk() may " /*
*/ "not be specified together"
di in red "the resulting terms would be collinear"
exit 198
}
if "`garch'`egarch'`pgarch'`sdgarch'" != "" & !$Tarchany {
di in red "garch(), egarch(), sdgarch(), and pgarch() " /*
*/ "options require that other"
di in red "arch terms be specified in the model"
exit 198
}
if "`tarch'" != "" & "`tparch'" != "" {
di in red "tarch() and tparch() may not be specified together"
di in red "the resulting terms would be collinear"
exit 198
}
if "`aparch'" != "" & "`aarch'" != "" {
di in red "aparch() and aarch() may not be specified together"
di in red "the resulting terms would be collinear"
exit 198
}
if "`archmexp'" != "" & "`archmlags'`archm'" == "" {
di in red "option archmexp() requires that archm or " /*
*/ "archmlags() be specified"
exit 198
}
if "`robust'" != "" & "`opg'" != "" {
local opg
di in gr "(note: option opg ignored when " /*
*/ "specified with robust)"
}
/* Handle ML options */
mlopts stdopts, `options'
local vcetype `hessian' `opg' `native' `robust'
local nvce : word count `vcetype'
if "`vce'" != "" {
local vcetype `vcetype' vce(`vce')
}
if (`nvce' + (`"`vce'"' != "")) > 1 {
di in red "options `:list retok vcetype' may not be combined"
exit 198
}
else local vce `vce' `hessian' `opg' `native'
if "`techniq'" == "" {
local tmeth `bhhh' `bhhhq' `bfgs' `dfp' `nr'
local ct : word count `tmeth'
local ct = `ct' + ("`bhhhbfgs'" != "") + ("`bhhhdfp'" != "")
if `ct' == 1 {
if "`bhhhbfgs'" != "" {
if "`vce'`robust'" == "" {
local vce opg
}
local tmeth ///
bhhh `:word 1 of `bhhhbfgs'' ///
bfgs `:word 2 of `bhhhbfgs''
}
if "`bhhhdfp'" != "" {
if "`vce'`robust'" == "" {
local vce opg
}
local tmeth ///
bhhh `:word 1 of `bhhhdfp'' ///
dfp `:word 2 of `bhhhdfp''
}
local techniq "technique(`tmeth')"
}
else if `ct' == 0 {
if "`vce'`robust'" == "" {
local vce opg
}
local techniq "technique(bhhh 5 bfgs 10)"
}
else {
di in red "may only specify one optimization method"
di in red "from: bhhh bfgs dfp nr bhhhbfgs() bhhhdfp()"
exit 198
}
}
else local techniq "technique(`techniq')" /* undoc */
if "`vce'" != "" {
local vce vce(`vce')
}
if "`nr'" != "" {
if "`difficu'" != "" { /* allow nodif */
local difficu ""
}
else local difficu "difficult" /* defalut to dif */
}
/* Process arch-in-mean terms */
if "`archm'" != "" {
local archm "0 `archmla'"
}
else local archm `archmla'
/* other special parsing */
if "`bracket'" == "" {
local bracket bracket
}
else local bracket
if "`from'" == "archb0" {
local archb0 "archb0"
local from
}
else if "`from'" == "armab0" {
local armab0 "armab0"
local from
}
else if "`from'" == "armab0 archb0" | "`from'" == "archb0 armab0" {
local archb0 "archb0"
local armab0 "armab0"
local from
}
local narch `narch'`narchk'
local nparch `nparch'`nparchk'
marksample touse /* set sample */
markout `touse' `het' `timevar' `panvar'
if "`savespa'" != "" {
preserve
tsrevar `varlist' `het', list
keep `r(varlist)' `touse' `timevar' `panvar'
qui tsset
}
/* Remove collinearity */
gettoken dep_m ind_m : varlist
_rmdcoll `varlist' if `touse', `constan'
local varlist `r(varlist)'
_rmcoll `het' if `touse'
local het `r(varlist)'
local ind_m `varlist'
global Tar `ar' /* globals, see bottom of file */
global Tma `ma'
global Tarch `arch'
global Tgarch `garch'
global Tarchm `archm'
global Ttarch `tarch'
global Ttparch `tparch'
global Tsaarch `saarch'
global Tabarch `abarch'
global Tatarch `atarch'
global Tparch `parch'
global Taarch `aarch'
global Tnarch `narch'
global Tearch `earch'
global Tegarch `egarch'
global Taparch `aparch'
global Tnparch `nparch'
global Tpgarch `pgarch'
global Tsdgarch `sdgarch'
/* Temporary variables for model
* components */
tempvar u e_t e2 sigma2 tvar
global Tu `u' /* errors, may be ARMA */
global Te `e_t' /* white noise disturbances (innov) */
global Te2 `e2' /* squared innovations for arch */
global Tsigma2 `sigma2' /* sigma^2 for arch = S_e = S */
global Ttvar `tvar'
qui gen double $Ttvar = . in 1
/* Parse ARMA and ARCH contitioning */
tempname sig2_0
global Tsig2_0 `sig2_0' /* scalar for priming values of s^2 */
if "`aarch'`aparch'`abarch'`atarch'`nparch'`narch'" != "" {
tempname abse_0
global Tabse_0 `abse_0'
}
/* Parse and set-up priming values */
tempname arprm maprm archprm garprm
if "$Tar$Tma" != "" { PrsArma0 , `arma0' }
global Tskipobs = max(0$Tskipobs, `condobs')
PrsArch0 , `arch0'
/* Starting values, matrix stripe
* and ML equations */
local yprefix `dep_m'
/* Xb */
tempname b0 T
if "`ind_m'" != "" | "`constan'" == "" {
capture regress `dep_m' `ind_m' if `touse' , `constan'
ErrCheck
qui predict double $Tu if `touse' , res
mat `b0' = e(b)
if index("`dep_m'", ".") == 0 {
global TXbeq `dep_m'
}
else global TXbeq "eq1"
local xbeqn "($TXbeq: `yprefix' = `ind_m', `constan')"
local yprefix
global Thasxb 1
/* maintain name stripe */
mat coleq `b0' = `dep_m'
local names : colfullnames `b0'
local colnams `colnams' `names'
}
else {
qui gen double $Tu = `dep_m'
global Thasxb 0
global Tdoxb "*"
}
/* arch-in-mean */
if "`archm'" != "" {
tempvar tarchm
global Ttarchm `tarchm'
qui gen double $Ttarchm = . in 1
if "`archmex'" != "" {
local archmx : /*
*/ subinstr local archmex "X" "$Tsigma2", all
global Tarchmex `archmx'
tempvar tarchme
global Ttarchme `tarchme'
qui gen double $Ttarchme = . in 1
AddStrip colnams : "`colnams'" "`archm'" ARCHM sigma2ex
}
else {
global Tdarchme "*"
local tarchme $Tsigma2
AddStrip colnams : "`colnams'" "`archm'" ARCHM sigma2
}
local ct : word count `archm'
mat `b0' = nullmat(`b0') , J(1, `ct', 0)
local ameaneq /*
*/ "(ARCHM: `yprefix' = l(`archm').`tarchme', nocons)"
local yprefix
}
else {
global Tdoarchm "*"
global Tdarchme "*"
global Ttarchm 0
}
/* AR, MA */
if "$Tar$Tma" != "" {
if "`ar'" != "" { local arterms "l(`ar').$Tu" }
if "`ma'" != "" { local materms "l(`ma').$Te" }
if "`armab0'" == "" {
/* Get residuals from AR representation of errors */
MinLag minlag : "$Tar" "$Tma"
MaxLagS maxlag : 2 "$Tar" "$Tma"
Monfort $Te : $Tu `minlag' `maxlag' `interva' `touse'
/* Get consistent estimates of AR and MA parameters */
capture regress $Tu `arterms' `materms' /*
*/ if `touse', nocons
if !_rc {
mat `T' = e(b)
FixARMA `T'
mat `b0' = nullmat(`b0') , `T'
}
else local armab0b "armab0"
}
if "`armab0'`armab0b'" != "" {
local narma : word count $Tar $Tma
mat `T' = J(1, `narma', 0)
mat `b0' = nullmat(`b0') , `T'
if "`armab0b'" == "" { qui gen double $Te = $Tu }
}
/* maintain name stripe */
AddStrip colnams : "`colnams'" "$Tar" ARMA ar
AddStrip colnams : "`colnams'" "$Tma" ARMA ma
/* ML equation */
local armaeqn "(ARMA: `yprefix' = `arterms' `materms', nocons )"
local yprefix
}
else {
global Tdoarma "*"
qui gen double $Te = $Tu
global Tu $Te
}
/* get estimate of e^2 */
qui gen double $Te2 = $Te^2
/* handle some cases of ARCH priming */
if "$Tarch0" == "xb0wt" | "$Tarch0" == "xbwt" {
tempname wt_e2 adj
global Ttimevar `timevar'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -