Page 1 of 1

Error in SVAR-GARCH code

Posted: Sun Feb 23, 2020 7:56 am
by leoleo73
Dear Tom Doan

I have still the same error because of the code in the the example 11.2 SVAR_GARCH impulse response in RATS handbook for ARCH/GARCH and Volatility model(2nd Edition)

frml SAVRLogl = hh=SVARHMatrix(t),sqrthoil=sqrt(hh(t)(1,1)),$
ux=SVARUVector(t),%logdensity(hh,ux) [/b]


## SX11. Identifier SVARHMATRIX is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>l = hh=SVARHMatrix(<<<<
If the name isn't mistyped, it's possible that you have a poorly formatted instruction
Common errors are
* a space before the ( in an option field
* a missing space before = in a SET or FRML
* a missing $ at the end of a long line which continues to the next

Please refer to the full text of coding below. And Please tell me what's wrong with below!

Code: Select all

open data oildata.rat
calendar(q) 1974:1
data(format=rats,compact=average) 1974:01 2013:01 ipdm rac gdpmc1
*
* The difference in data preparation is that Elder and Serletis use * the final period within the quarter for the (monthly source) RAC,
* while this uses the quarterly average. The quarterly average
* matches the timing on GDP and the deflator.
*
* Data are annualized growth rates
*
set realoil = rac/ipdm
set oilgrow = 400.0*log(realoil/realoil{1})
set gdpgrow = 400.0*log(gdpmc1/gdpmc1{1})
*
compute nlags=4
set sqrthoil = 0.0
*
* Set up the VAR including the square root of oil (which will be
* generated recursively) as one of the regressors.
*
system(model=basevar)
variables oilgrow gdpgrow
lags 1 to nlags
det constant sqrthoil
end(system)
*
* This is the position of the "M" effect coefficient
*
compute meffectpos=2*nlags+2
*
compute n=2
dec vect[series] y(n)
set y(1) = oilgrow
set y(2) = gdpgrow
*
* Estimate the OLS VAR
*
estimate(resids=u)
compute gstart=%regstart(),gend=%regend()
*
* Parameters for the GARCH processes for the orthogonal V *
dec vect[vect] g(n)
dec vect[vect] bvec(n)
dec vect[equation] garchmeqns(n)
do i=1,n
compute garchmeqns(i)=%modeleqn(basevar,i)
compute bvec(i)=%eqncoeffs(garchmeqns(i))
compute g(i)=||%sigma(i,i)*(1-.20-.60),.20,.60||
end do i
************************************************************
* B-matrix loading for the SVAR
*
dec frml[rect] bfrml
dec real b
*
frml bfrml = ||$
1.0,0.0|b,1.0||
compute b=0.0
*
nonlin(parmset=svarparms) bvec b
nonlin(parmset=garchparms) g
*
* Series for recursions on the variances
*
dec series[symm] vv
dec series[vect] hhd
dec series[symm] hh
dec rect binv
*
gset hhd 1 gend = %zeros(n,1)
gset hh 1 gend = %zeros(n,n)
gset vv 1 gend = %zeros(n,n)
***************************** 
* This is a "startup" function which needs to be executed at the
* start of a function evaluation. The B matrix and its inverse
* change with the parameters, but not with time. And we need to get
* the transformed pre-sample values.
*
function SVARStart
local symm vsigma
*
compute bmat=bfrml(1)
compute binv=inv(bmat)
compute vsigma=binv*%sigma*tr(binv)
gset hhd 1 gstart-1 = %xdiag(vsigma)
gset vv 1 gstart-1 = vsigma
end
************
***********************************************************
* This is the function evaluated at each entry to compute the
* residuals. It also saves the outer product of the structural
* residuals for use in the GARCH recursion. *
function SVARUVector t
type vect SVARUVector
type integer t
*
local integer i
*
do i=1,%nvar
compute u(i)(t) = y(i)(t)-%eqnvalue(garchmeqns(i),t,bvec(i))
end do i
compute vv(t)=%outerxx(binv*%xt(u,t))
compute SVARUVector=%xt(u,t)
end
*********************************************************************
*
* This computes the logl likelihood by computing the covariance
* matrix, then the square root of the oil shock variance, then the
* residuals. It has to be done in that order since current sqrthoil
* is needed in the formula for the residuals.
frml SAVRLogl = hh=SVARHMatrix(t),sqrthoil=sqrt(hh(t)(1,1)),$
ux=SVARUVector(t),%logdensity(hh,ux)