## Panel Garch: coding general mean and conditional varian

Discussions of ARCH, GARCH, and related models

### Panel Garch: coding general mean and conditional varian

CAN YOU HELP PLEASE I AM A NEW USER. I AM USING THE ESTIMA PANEL GARCH (1,1) EXAMPLE WITH THEIR XRATE DATA (FOR CONVENIENCE TO GET CODING CORRECT). I WILL EVENTUALLY APPLY TO A LARGER PANEL OF RETURNS WITH MORE DUMMIES AND POSSIBLY MORE AR TERMS. TO START I HAVE INCORPORATED ONE DUMMY AND ONE AR(1) TERM INTO THE MEAN EQUATION.
I NOW WISH TO ADD THE DUMMY VARIABLE TO THE VARIANCE EQU TO GET ITS OVERALL EFFECT ON THE CONDITIONAL VARIANCE OF THE PANEL. ALSO MAY WISH TO ADD FURTHER LAGGED VALUES OF UU TO THE CONDITIONAL VARIANCE. I ATTACH THE PRG BELOW. THANK YOU IN ADVANCE.

Code: Select all
`all 6237    open data g10xrate.xls    data(format=xls,org=columns) / usxjpn usxfra usxsui*Bring in  dummy, say E.G. at obs 3000. Note that this is an identical dummy applied to each i in the panel   dummy(ao=3000) dumann1 /   dummy(ao=3000) dumann2 /   dummy(ao=3000) dumann3 /   *print / dumann1    *    set xjpn = 100.0*log(usxjpn/usxjpn{1})    set xfra = 100.0*log(usxfra/usxfra{1})    set xsui = 100.0*log(usxsui/usxsui{1})    *    * Estimation using MAXIMIZE    * The initial few lines of this set the estimation range, which needs to    * be done explicitly, and the number of variables. Then, vectors for the    * dependent variables, residuals and residuals formulas are set up. The    * SET instructions copy the dependent variables over into the slots in    * the vector of series.    *    compute gstart=3,gend=6237    compute n=3    dec vect[series] y(n) u(n) yl1(n) dumann(n)    dec vect[frml] resid(n)    set y(1) = xjpn    set y(2) = xfra    set y(3) = xsui    set yl1(1) = xjpn{1}   set yl1(2) = xfra{1}   set yl1(3) = xsui{1}   set dumann(1) = dumann1   set dumann(2) = dumann2   set dumann(3) = dumann3    *    * This is specific to a mean-only model. It sets up the formulas (the &i    * are needed in the formula definitions when the FRML is defined in a    * loop), and estimates them using NLSYSTEM. This both initializes the    * mean parameters, and computes the unconditional covariance matrix. If    * you want more general mean equations, the simplest way to do that    * would be to define each FRML separately.    *   dec vect b(n) ar(n) d(n)      * Do it first with separate frms's    *nonlin(parmset=meanparms) b1 b2 b3 ar1 ar2 ar3 d1 d2 d3    *frml resid(1) = y(1)-b1-ar1*yl1(1)-d1*dumann(1)   *frml resid(2) = y(2)-b2-ar2*yl1(2)-d2*dumann(2)   *frml resid(3) = y(3)-b3-ar3*yl1(3)-d3*dumann(3)      * Now do it in a loop to see if identical to above   nonlin(parmset=meanparms) b ar d    do i=1,n       frml resid(i) = (y(&i)-b(&i)-ar(&i)*yl1(&i)-d(&i)*dumann(&i))    end do i    nlsystem(parmset=meanparms,resids=u) gstart gend resid    compute rr=%sigma   display rr    *    * The paths of the covariance matrices and uu' are saved in the    * SERIES[SYMM] names H and UU. UX and HX are used to pull in residuals    * and H matrices.    *    declare series[symm] h uu     *    * ux is used when extracting a u vector    *    declare symm hx(n,n)    declare vect ux(n)    *    * These are used to initialize pre-sample variances.    *    gset h  * gend = rr    gset uu * gend = rr    *    * This is a standard (normal) log likelihood formula for any    * multivariate GARCH model. The difference among these will be in the    * definitions of HF and RESID. The function %XT pulls information out of    * a matrix of SERIES.    *    declare frml[symm] hf    *    frml logl = \$        hx = hf(t) , \$        %do(i,1,n,u(i)=resid(i)) , \$        ux = %xt(u,t), \$        h(t)=hx, uu(t)=%outerxx(ux), \$        %logdensity(hx,ux)    *****************************************************    *    * Panel GARCH - DVECH with restrictions. WISH TO ADD THE DUMMY VARIABLE ABOVE TO THE VARIANCE EQU TO GET ITS OVERALL EFFECT ON THE CONDITIONAL VARIANCE OF **THE PANEL. ALSO MAY WISH TO ADD FURTHER LAGGED VALUES OF UU       dec symm vcs(n,n)    dec real delta lambda gamma rho duma    dec symm vbs(n,n) vas(n,n) vdann(n,n)     *    compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1    nonlin(parmset=garchparms) vcs delta lambda gamma rho     frml hf = vcs+vbs.*h{1}+vas.*uu{1}    *    * Call once during START option to fill in the VAS and VBS arrays    *    function PGARCHInit    local integer i j    ewise vbs(i,j)=%if(i==j,delta,lambda)    ewise vas(i,j)=%if(i==j,gamma,rho)    end    *    maximize(start=PGARCHInit(),parmset=meanparms+garchparms,pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend`
trish

Posts: 3
Joined: Wed Apr 04, 2012 4:49 am

### Re: Panel Garch: coding general mean and conditional varian

Are you always using the same dummies for each i, just with different loadings? If so, you would just make the following adjustments:

dec symm vcs(n,n) vds(n,n)
dec real delta lambda gamma rho duma
dec symm vbs(n,n) vas(n,n) vdann(n,n)
*
compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1
compute vds=%zeros(n,n)
nonlin(parmset=garchparms) vcs vds delta lambda gamma rho
frml hf = vcs+vds*dumann1+vbs.*h{1}+vas.*uu{1}
TomDoan

Posts: 2761
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Panel Garch: coding general mean and conditional varian

Cheers and thank you for your prompt reply and for this solution. At the moment I am using the same dummies for each i but as I take the project forward this will change.
trish

Posts: 3
Joined: Wed Apr 04, 2012 4:49 am

### Re: Panel Garch: coding general mean and conditional varian

Hi Tom
Re above, I would be grateful if you could show me how to cope with different mean and variance slope dummies, say e.g. Dy1t*rt; Dy2t*rt; Dy3t*rt, where Dyit take different time series values of 1 and 0 depending on the variable being analyzed, (e.g. in the above example, y1=xjpn, y2=xfra, y3=xsui) and rt is an exogenous time series.
trish

Posts: 3
Joined: Wed Apr 04, 2012 4:49 am

### Re: Panel Garch: coding general mean and conditional varian

Hello Tom:

Forgive me for asking a truly embarrassing question. After running the program below, how do save the residuals and conditional variance for further analysis? I have typed the following commands after the "maximize" statement without much success:

open copy mil_firms.xls
copy(format=xls,org=cols) gstart gend nresids cvar

Unfortunately, I have not used RATS for a while and feel totally rusty. Help me please.

Mbodja

Code: Select all
`all 6237    open data g10xrate.xls    data(format=xls,org=columns) / usxjpn usxfra usxsui*Bring in  dummy, say E.G. at obs 3000. Note that this is an identical dummy applied to each i in the panel   dummy(ao=3000) dumann1 /   dummy(ao=3000) dumann2 /   dummy(ao=3000) dumann3 /   *print / dumann1    *    set xjpn = 100.0*log(usxjpn/usxjpn{1})    set xfra = 100.0*log(usxfra/usxfra{1})    set xsui = 100.0*log(usxsui/usxsui{1})    *    * Estimation using MAXIMIZE    * The initial few lines of this set the estimation range, which needs to    * be done explicitly, and the number of variables. Then, vectors for the    * dependent variables, residuals and residuals formulas are set up. The    * SET instructions copy the dependent variables over into the slots in    * the vector of series.    *    compute gstart=3,gend=6237    compute n=3    dec vect[series] y(n) u(n) yl1(n) dumann(n)    dec vect[frml] resid(n)    set y(1) = xjpn    set y(2) = xfra    set y(3) = xsui    set yl1(1) = xjpn{1}   set yl1(2) = xfra{1}   set yl1(3) = xsui{1}   set dumann(1) = dumann1   set dumann(2) = dumann2   set dumann(3) = dumann3    *    * This is specific to a mean-only model. It sets up the formulas (the &i    * are needed in the formula definitions when the FRML is defined in a    * loop), and estimates them using NLSYSTEM. This both initializes the    * mean parameters, and computes the unconditional covariance matrix. If    * you want more general mean equations, the simplest way to do that    * would be to define each FRML separately.    *   dec vect b(n) ar(n) d(n)      * Do it first with separate frms's    *nonlin(parmset=meanparms) b1 b2 b3 ar1 ar2 ar3 d1 d2 d3    *frml resid(1) = y(1)-b1-ar1*yl1(1)-d1*dumann(1)   *frml resid(2) = y(2)-b2-ar2*yl1(2)-d2*dumann(2)   *frml resid(3) = y(3)-b3-ar3*yl1(3)-d3*dumann(3)      * Now do it in a loop to see if identical to above   nonlin(parmset=meanparms) b ar d    do i=1,n       frml resid(i) = (y(&i)-b(&i)-ar(&i)*yl1(&i)-d(&i)*dumann(&i))    end do i    nlsystem(parmset=meanparms,resids=u) gstart gend resid    compute rr=%sigma   display rr    *    * The paths of the covariance matrices and uu' are saved in the    * SERIES[SYMM] names H and UU. UX and HX are used to pull in residuals    * and H matrices.    *    declare series[symm] h uu     *    * ux is used when extracting a u vector    *    declare symm hx(n,n)    declare vect ux(n)    *    * These are used to initialize pre-sample variances.    *    gset h  * gend = rr    gset uu * gend = rr    *    * This is a standard (normal) log likelihood formula for any    * multivariate GARCH model. The difference among these will be in the    * definitions of HF and RESID. The function %XT pulls information out of    * a matrix of SERIES.    *    declare frml[symm] hf    *    frml logl = \$        hx = hf(t) , \$        %do(i,1,n,u(i)=resid(i)) , \$        ux = %xt(u,t), \$        h(t)=hx, uu(t)=%outerxx(ux), \$        %logdensity(hx,ux)    *****************************************************    *    * Panel GARCH - DVECH with restrictions. WISH TO ADD THE DUMMY VARIABLE ABOVE TO THE VARIANCE EQU TO GET ITS OVERALL EFFECT ON THE CONDITIONAL VARIANCE OF **THE PANEL. ALSO MAY WISH TO ADD FURTHER LAGGED VALUES OF UU       dec symm vcs(n,n)    dec real delta lambda gamma rho duma    dec symm vbs(n,n) vas(n,n) vdann(n,n)     *    compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1    nonlin(parmset=garchparms) vcs delta lambda gamma rho     frml hf = vcs+vbs.*h{1}+vas.*uu{1}    *    * Call once during START option to fill in the VAS and VBS arrays    *    function PGARCHInit    local integer i j    ewise vbs(i,j)=%if(i==j,delta,lambda)    ewise vas(i,j)=%if(i==j,gamma,rho)    end    *    maximize(start=PGARCHInit(),parmset=meanparms+garchparms,pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend`
debkaplan1970

Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

### Re: Panel Garch: coding general mean and conditional varian

This is set up to give very similar results to a GARCH instruction. The residuals are in a VECT[SERIES] called U, so

open copy mil_firms.xls
copy(format=xls,org=cols) gstart gend u

will give you an XLS file with the residuals (in separate columns) for each variable.

The covariances are in a SERIES[SYMM] called HH. You have to split those off into separate series in order to export them. For instance

set h11 gstart gend = hh(t)(1,1)
set h12 gstart gend = hh(t)(1,2)

etc.
TomDoan

Posts: 2761
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Panel Garch: coding general mean and conditional varian

Dear Tom:

Thanks for your swift response. Regrettably, I am still not able to retrieve the residuals and the conditional variance following your guidance. Again I apologize for being such a nuisance but I don't know who else to turn to for help about this matter. Thank you so much.
debkaplan1970

Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

### Re: Panel Garch: coding general mean and conditional varian

debkaplan1970 wrote:Dear Tom:

Thanks for your swift response. Regrettably, I am still not able to retrieve the residuals and the conditional variance following your guidance. Again I apologize for being such a nuisance but I don't know who else to turn to for help about this matter. Thank you so much.

You'd have to post what you tried that didn't work.
TomDoan

Posts: 2761
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Panel Garch: coding general mean and conditional varian

The following is what I ran. I do get the estimates of the GARCH model. However, I am not able to retrieve the residual and conditional variance. Thanks again.

_______________________________________________________________________________________
Code: Select all
`all 8000OPEN DATA " C:\Documents and Settings\~oreo~\My Documents\WinRATS Standard 8.1\garch_data_2004.xls"DATA(FORMAT=XLS,ORG=COLUMNS) 1 8000 elec_news_date PERMNO PERMCO HSICCD PRC VOL RET SHROUT vwretd stock_date year time**set xjpn = 100.0*log(usxjpn/usxjpn{1})    *set xfra = 100.0*log(usxfra/usxfra{1})    *set xsui = 100.0*log(usxsui/usxsui{1})    *    * Estimation using MAXIMIZE    * The initial few lines of this set the estimation range, which needs to be done explicitly, and the number of variables.    * Then, vectors for the dependent variables, residuals and residuals formulas * are set up. The SET instructions copy**slots in the vector of series.    *    compute gstart=2,gend=8000    compute n=2    dec vect[series] y(n) u(n)    dec vect[frml] resid(n)    set y(1) = ret    set y(2) = vwretd    *    * This is specific to a mean-only model. It sets up the formulas (the &I are needed in the formula definitions when the FRML is defined in a loop), and estimates them using NLSYSTEM.     * This both initializes the mean parameters, and c matrix. If you want more general mean equations, the simplest way to do that would be to define each FRML separately.    *    dec vect b(n)    nonlin(parmset=meanparms) b    do i=1,n       frml resid(i) = (y(&i)-b(&i))    end do i    nlsystem(parmset=meanparms,resids=u) gstart gend resid    compute rr=%sigma    *    * The paths of the covariance matrices and uu' are saved in the    * SERIES[SYMM] names H and UU. UX and HX are used to pull in residuals and H matrices.    *    declare series[symm] h uu    *    * ux is used when extracting a u vector    *    declare symm hx(n,n)    declare vect ux(n)    *    * These are used to initialize pre-sample variances.    *    gset h  * gend = rr    gset uu * gend = rr    *    * This is a standard (normal) log likelihood formula for any multivariate GARCH model. The difference among these will be in the definitions of HF and RESID.     * The function %XT pulls information out of a matrix of SERIES.    *    declare frml[symm] hf    *    frml logl = \$        hx = hf(t) , \$        %do(i,1,n,u(i)=resid(i)) , \$        ux = %xt(u,t), \$        h(t)=hx, uu(t)=%outerxx(ux), \$        %logdensity(hx,ux)    *****************************************************    *    * Panel GARCH - DVECH with restrictions    *    dec symm vcs(n,n)    dec real delta lambda gamma rho    dec symm vbs(n,n) vas(n,n)    *    compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1    nonlin(parmset=garchparms) vcs delta lambda gamma rho    frml hf = vcs+vbs.*h{1}+vas.*uu{1}    *    * Call once during START option to fill in the VAS and VBS arrays    *    function PGARCHInit    local integer i j    ewise vbs(i,j)=%if(i==j,delta,lambda)    ewise vas(i,j)=%if(i==j,gamma,rho)    end    *maximize(start=PGARCHInit(),parmset=meanparms+garchparms,pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend *open copy mil_firms.xlscopy(format=xls,org=cols) gstart gend u`
debkaplan1970

Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

### Re: Panel Garch: coding general mean and conditional varian

I'm not sure what you mean by not being able to retrieve the residuals. The residuals should be in the Excel file that you created.
TomDoan

Posts: 2761
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Panel Garch: coding general mean and conditional varian

The residuals should be in the Excel file I created but no such file is being created. This is so frustrating and embarrassing.
debkaplan1970

Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

### Re: Panel Garch: coding general mean and conditional varian

It has to be created. Put a full path name on it so you know exactly where it's going.
TomDoan

Posts: 2761
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Panel Garch: coding general mean and conditional varian

Hello
I am new to this forum. also i am new to RATS.
after working few days with manuals etc i got an idea about RATS.
I want to do Panel GARCH estimation. I got a code from this forum and generalize it for my number of cross sections.
now what i want to include a variable (in panel form) in variance equation.
for example
Hit = a + b hit-1 + c uit-1 + d Xit
i am intended to include this Xit in variance "Hit" equation. can you please help me how to do it in this Code?
Rest i will do.
Thanks.
suhriz

Posts: 2
Joined: Thu Jun 13, 2013 2:29 am

### Re: Panel Garch: coding general mean and conditional varian

suhriz wrote:Hello
I am new to this forum. also i am new to RATS.
after working few days with manuals etc i got an idea about RATS.
I want to do Panel GARCH estimation. I got a code from this forum and generalize it for my number of cross sections.
now what i want to include a variable (in panel form) in variance equation.
for example
Hit = a + b hit-1 + c uit-1 + d Xit
i am intended to include this Xit in variance "Hit" equation. can you please help me how to do it in this Code?
Rest i will do.
Thanks.

I'm not sure if you found the original post (rather than the ones above where users have already made changes). That's at viewtopic.php?f=11&t=715. How did you want to handle the "shape" of the effects of X_it? The panel GARCH model has freely estimated variance intercepts with lagged variance and lagged squared residuals terms which each have only one of two parameters (for diagonal and off-diagonal). Which handling did you want for the X_it coefficients?
TomDoan

Posts: 2761
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Panel Garch: coding general mean and conditional varian

Dear Tom,
let me first show you code i have generalized for 4 firms from 3. code with 3 were given on link you mentioned here (thanks for that).
I edited the code for 4 firms. and also entered the Xit variable in variance equation.
Have a look at it:
OPEN DATA "C:\Users\SuhRiz\Desktop\short sale.xls"
DATA(FORMAT=XLS,ORG=COLUMNS) 1 944 abank bbank cbank dbank dabank dbbank dcbank ddbank
* Estimation using MAXIMIZE
* The initial few lines of this set the estimation range, which needs to
* be done explicitly, and the number of variables. Then, vectors for the
* dependent variables, residuals and residuals formulas are set up. The
* SET instructions copy the dependent variables over into the slots in
* the vector of series.
*
compute gstart=5,gend=900 ;* set the estimation range
compute n=4 ;*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< # variables
dec vect[series] y(n) u(n) yL1(n) dumann(n)
dec vect[frml] resid(n)

set y(1) = abank
set y(2) = bbank
set y(3) = cbank
set y(4) = dbank

set yL1(1) = abank{1}
set yL1(2) = bbank{1}
set yL1(3) = cbank{1}
set yL1(4) = dbank{1}

set dumann(1) = dabank
set dumann(2) = dbbank
set dumann(3) = dcbank *these 4 are variable vector which we want to introduce in variance equation
set dumann(4) = ddbank

*

* This is specific to a mean-only model. It sets up the formulas (the &i
* are needed in the formula definitions when the FRML is defined in a
* loop), and estimates them using NLSYSTEM. This both initializes the
* mean parameters, and computes the unconditional covariance matrix. If
* you want more general mean equations, the simplest way to do that
* would be to define each FRML separately.

*
dec vect b(n) ar(n)
* Now do it in a loop to see if identical to above
nonlin(parmset=meanparms) b ar
do i=1,n

frml resid(i) = (y(&i)-b(&i)-ar(&i)*yL1(&i))

end do i
nlsystem(parmset=meanparms,resids=u) gstart gend resid
compute rr=%sigma
display rr

*
* The paths of the covariance matrices and uu' are saved in the
* SERIES[SYMM] names H and UU. UX and HX are used to pull in residuals
* and H matrices.
*
declare series[symm] h uu
*
* ux is used when extracting a u vector
*
declare symm hx(n,n)
declare vect ux(n)
*
* These are used to initialize pre-sample variances.
*
gset h * gend = rr
gset uu * gend = rr
*
* This is a standard (normal) log likelihood formula for any
* multivariate GARCH model. The difference among these will be in the
* definitions of HF and RESID. The function %XT pulls information out of
* a matrix of SERIES.
*
declare frml[symm] hf
*
frml logl = \$
hx = hf(t) , \$
%do(i,1,n,u(i)=resid(i)) , \$
ux = %xt(u,t), \$
h(t)=hx, uu(t)=%outerxx(ux), \$
%logdensity(hx,ux)
*****************************************************
*
* Panel GARCH - DVECH with restrictions. WISH TO ADD THE DUMMY VARIABLE ABOVE TO THE VARIANCE EQU TO GET ITS OVERALL EFFECT ON THE CONDITIONAL VARIANCE OF **THE PANEL. ALSO MAY WISH TO ADD FURTHER LAGGED VALUES OF UU
dec symm vcs(n,n) vds(n,n)
dec real delta lambda gamma rho duma theta
dec symm vbs(n,n) vas(n,n) vdann(n,n)
*
compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1
compute vds=%zeros(n,n)
nonlin(parmset=garchparms) vcs delta lambda gamma rho duma theta
frml hf = vcs+vds*dumann(&i)+vbs.*h{1}+vas.*uu{1}

* Call once during START option to fill in the VAS and VBS arrays
*
function PGARCHInit
local integer i j
ewise vbs(i,j)=%if(i==j,delta,lambda)
ewise vas(i,j)=%if(i==j,gamma,rho)
ewise vds(i,j)=%if(i==j,duma,theta)

end
*
maximize(start=PGARCHInit(),parmset=meanparms+garchparms,pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend

------------------------------------------------------------------------------------------------

Now my confusions are:

1. Which one from Delta and Lambda is coefficient of lag variance term?
2. compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1-----in this compute command what these initial values are? Are these initial values for maximum likelihood? And should we give these values to our variables’s “Duma and Theta in this case” coefficients? If yes then what values we should give?
3. VCS are the intercepts? Am I right? And we are not pooling it so that we can have different intercept for different company? Am I right sir?
4. Which one from Duma and theta will be the coefficient of our variable which we have introduced in variance equation?

I am new to this programming and coding. so evaluate this code and give comments on its correctness.
NOTE: i have estimated this code and results are without any error.
Thanks a bunch.
suhriz

Posts: 2
Joined: Thu Jun 13, 2013 2:29 am