Page 1 of 1

Bivariate EGARCH with Panel Data

Posted: Fri Sep 09, 2011 12:03 am
by jma42
Hi,

This is the first time I post here. The forum has been greatly helpful for me in terms of EViews usage and programming. Hopefully my questions can be solved here and the post can provide useful information to other users.

I am working on a research project studying the relationship between exchange rate changes and stock returns in panel data context using bivariate EGARCH (Nelson 1991) with time-varying conditional correlation (the original constant correlation coefficient proposed by Nelson was relaxed by Darbar and Deb, 2002). A number of papers used this methodology, e.g. Skintzi and Refenes (2006) "Volatility Spillovers and Dynamic Correlation in European Bond Markets" and Bhar and Nikolova (2009) "Return, volatility spillovers and dynamic correlation in the BRIC equity markets- An analysis using a bivariate EGARCH framework".

However, as we all know, EViews does not provide ARCH type estimation in a panel structure workfile. So I tried to write a bivariate EGARCH programme in simple time series environment hoping that it will work in the panel data context. Fortunately the program worked fine in an unstacked workfile. So I did some modification to the programme (e.g. change the univariate GARCH estimation for the starting value of the coefficients to a simple OLS estimation using squared errors as a proxy of the conditional variance) and apply it to a stacked panel structure workfile.

But when I run the programme, the EViews keeps telling me that there is a missing value in the 2nd period of the log likelihood sample. I even tried to set the sample to a single individual so that the estimation should be exactly the same with the unstacked file. But the programme was still not working.

Can someone good at this help me have a look and see what the problem is?

Attached is the stacked and unstacked programmes and the related workfiles. (the {%x} is just a notation for myself to know which country (in unstacked file) or set of effects (in stacked file) I am working on. hopefully it won't cause to much trouble in reading.)

Cheers
stacked.wf1
(670.62 KiB) Downloaded 663 times
unstacked-try.wf1
(286.9 KiB) Downloaded 645 times

Code: Select all

'change path to program path %path=@runpath cd %path 'load workfile containing the return series load stacked.wf1 smpl @all %x ="ni" !p = 4 !q = 2 'Estimate the conditional mean using VAR var {%x}_var.ls 1 !p e s @ show {%x}_var.output 'Generate residual series form var {%x}_var.makeresids() {%x}_e {%x}_s series {%x}_sqe ={%x}_e^2 series {%x}_sqs ={%x}_s^2 series {%x}_z_e ={%x}_e/@sqrt(@var({%x}_e)) series {%x}_z_s ={%x}_s/@sqrt(@var({%x}_s)) ' set sample ' first observation of s1 need to be one or two periods after the first observation of s0 sample s0 2/5/1999 8/26/2011 sample s1 2/19/1999 8/26/2011 ' initialization of parameters and starting values smpl s0 'get starting values from univariate GARCH equation {%x}_pre_e.ls {%x}_sqe c abs({%x}_z_e) {%x}_z_e abs({%x}_z_s) {%x}_z_s {%x}_sqe(-1 to -!q) equation {%x}_pre_s.ls {%x}_sqs c abs({%x}_z_e) {%x}_z_e abs({%x}_z_s) {%x}_z_s {%x}_sqs(-1 to -!q) ' declare coef vectors to use in bi-variate Panel EGARCH model coef(2) {%x}_alpha0 {%x}_alpha0(1)= {%x}_var.c(1,1+2*!p) {%x}_alpha0(2)= {%x}_var.c(2,1+2*!p) for !n=1 to !p coef(4) {%x}_alpha!n {%x}_alpha!n(1)= {%x}_var.c(1,!n) {%x}_alpha!n(2)= {%x}_var.c(1,!n+!p) {%x}_alpha!n(3)= {%x}_var.c(2,!n) {%x}_alpha!n(4)= {%x}_var.c(2,!n+!p) next coef(2) {%x}_beta0 {%x}_beta0(1)= {%x}_pre_e.c(1) {%x}_beta0(2)= {%x}_pre_s.c(1) coef(4) {%x}_beta1 {%x}_beta1(1)={%x}_pre_e.c(2) {%x}_beta1(2)={%x}_pre_e.c(4) {%x}_beta1(3)={%x}_pre_s.c(2) {%x}_beta1(4)={%x}_pre_s.c(4) coef(2) {%x}_delta {%x}_delta(1) = {%x}_pre_e.c(3)/{%x}_pre_e.c(2) {%x}_delta(2) = {%x}_pre_s.c(5)/{%x}_pre_s.c(4) for !m=1 to !q coef(2) {%x}_gamma!m {%x}_gamma!m(1)= {%x}_pre_e.c(!m+5) {%x}_gamma!m(2)= {%x}_pre_s.c(!m+5) next coef(3) {%x}_eta {%x}_eta(1) = 0.5 {%x}_eta(2) = 0.05 {%x}_eta(3) = 0.9 ' use var-cov of sample in "s0" as starting value of variance-covariance matrix series {%x}_var_e = @var({%x}_e) series {%x}_var_s = @var({%x}_s) series {%x}_xi = -log((1-@cor({%x}_e,{%x}_s))/(1+@cor({%x}_e,{%x}_s))) series {%x}_cor=2/(1+@exp(-{%x}_xi))-1 series {%x}_cov={%x}_cor*@sqrt(@var({%x}_e)*@var({%x}_s)) scalar E_z=@sqrt(2/@acos(-1)) ' ........................................................... ' LOG LIKELIHOOD ' set up the likelihood ' 1) open a new blank likelihood object (L.O.) name bvegarch ' 2) specify the log likelihood model by append ' ........................................................... logl {%x}_bvegarch {%x}_bvegarch.append @logl logl {%x}_bvegarch.append {%x}_e = E - ({%x}_alpha0(1) + {%x}_alpha1(1)*E(-1) + {%x}_alpha2(1)*E(-2) + {%x}_alpha3(1)*E(-3) + {%x}_alpha4(1)*E(-4) + {%x}_alpha1(2)*S(-1) + {%x}_alpha2(2)*S(-2) + {%x}_alpha3(2)*S(-3) + {%x}_alpha4(2)*S(-4)) {%x}_bvegarch.append {%x}_s = S - ({%x}_alpha0(2) + {%x}_alpha1(3)*E(-1) + {%x}_alpha2(3)*E(-2) + {%x}_alpha3(3)*E(-3) + {%x}_alpha4(3)*E(-4) + {%x}_alpha1(4)*S(-1) + {%x}_alpha2(4)*S(-2) + {%x}_alpha3(4)*S(-3) + {%x}_alpha4(4)*S(-4)) {%x}_bvegarch.append {%x}_z_e = {%x}_e/@sqrt(@var({%x}_e)) {%x}_bvegarch.append {%x}_z_s = {%x}_s/@sqrt(@var({%x}_s)) ' calculate the variance and covariance series {%x}_bvegarch.append log({%x}_var_e) = {%x}_beta0(1) + {%x}_beta1(1)*(abs({%x}_z_e(-1))-E_z+{%x}_delta(1)*{%x}_z_e(-1)) + {%x}_beta1(2)*(abs({%x}_z_s(-1))-E_z+{%x}_delta(2)*{%x}_z_s(-1)) + {%x}_gamma1(1)*log({%x}_var_e(-1)) + {%x}_gamma2(1)*log({%x}_var_e(-2)) {%x}_bvegarch.append log({%x}_var_s) = {%x}_beta0(2) + {%x}_beta1(3)*(abs({%x}_z_e(-1))-E_z+{%x}_delta(1)*{%x}_z_e(-1)) + {%x}_beta1(4)*(abs({%x}_z_s(-1))-E_z+{%x}_delta(2)*{%x}_z_s(-1)) + {%x}_gamma1(2)*log({%x}_var_s(-1)) + {%x}_gamma2(2)*log({%x}_var_s(-2)) {%x}_bvegarch.append {%x}_z_e = {%x}_e/@sqrt({%x}_var_e) {%x}_bvegarch.append {%x}_z_s = {%x}_s/@sqrt({%x}_var_s) {%x}_bvegarch.append {%x}_xi = {%x}_eta(1) + {%x}_eta(2)*{%x}_z_e(-1)*{%x}_z_s(-1) + {%x}_eta(3)*{%x}_xi(-1) {%x}_bvegarch.append {%x}_cor=2/(1+@exp(-{%x}_xi))-1 {%x}_bvegarch.append {%x}_cov={%x}_cor*@sqrt({%x}_var_e*{%x}_var_s) ' determinant of the variance-covariance matrix {%x}_bvegarch.append {%x}_deth = {%x}_var_e*{%x}_var_s - {%x}_cov^2 ' log-likelihood series {%x}_bvegarch.append logl =-0.5*(2*17*(660-!p)*log(2*@acos(-1)) + log({%x}_deth) + ({%x}_e^2*{%x}_var_s + {%x}_s^2*{%x}_var_e - 2*{%x}_cov*{%x}_e*{%x}_s)/{%x}_deth) ' estimate the model smpl s1 {%x}_bvegarch.ml(showopts, m=500, c=1e-6) ' change below to display different output show {%x}_bvegarch.output graph {%x}_vare.line {%x}_var_e graph {%x}_vars.line {%x}_var_s graph {%x}_coves.line {%x}_cov graph {%x}_cores.line {%x}_cor show {%x}_vare show {%x}_vars show {%x}_coves show {%x}_cores

Code: Select all

'change path to program path %path=@runpath cd %path 'load workfile containing the return series load unstacked.wf1 smpl @all %x ="us" !p = 4 !q = 2 'Estimate the conditional mean using VAR var {%x}_var.ls 1 !p e_{%x} s_{%x} @ show {%x}_var.output 'Generate residual series form var {%x}_var.makeresids() {%x}_e {%x}_s ' set sample ' first observation of s1 need to be one or two periods after the first observation of s0 sample s0 2/5/1999 8/26/2011 sample s1 2/19/1999 8/26/2011 ' initialization of parameters and starting values smpl s0 'get starting values from univariate GARCH equation {%x}_egarch1.ARCH(1,!q,EGARCH,H,BACKCAST=0.7,DERIV=AA) {%x}_e equation {%x}_egarch2.ARCH(1,!q,EGARCH,H,BACKCAST=0.7,DERIV=AA) {%x}_s ' declare coef vectors to use in bi-variate Panel EGARCH model coef(2) {%x}_alpha0 {%x}_alpha0(1)= {%x}_var.c(1,1+2*!p) {%x}_alpha0(2)= {%x}_var.c(2,1+2*!p) for !n=1 to !p coef(4) {%x}_alpha!n {%x}_alpha!n(1)= {%x}_var.c(1,!n) {%x}_alpha!n(2)= {%x}_var.c(1,!n+!p) {%x}_alpha!n(3)= {%x}_var.c(2,!n) {%x}_alpha!n(4)= {%x}_var.c(2,!n+!p) next coef(2) {%x}_beta0 {%x}_beta0(1)= {%x}_egarch1.c(1) {%x}_beta0(2)= {%x}_egarch2.c(1) coef(4) {%x}_beta1 {%x}_beta1(1)={%x}_egarch1.c(2) {%x}_beta1(2)=0 {%x}_beta1(3)=0 {%x}_beta1(4)={%x}_egarch2.c(2) coef(2) {%x}_delta {%x}_delta(1) = {%x}_egarch1.c(3)/{%x}_egarch1.c(2) {%x}_delta(2) = {%x}_egarch2.c(3)/{%x}_egarch2.c(2) for !m=1 to !q coef(2) {%x}_gamma!m {%x}_gamma!m(1)= {%x}_egarch1.c(!m+3) {%x}_gamma!m(2)= {%x}_egarch2.c(!m+3) next coef(3) {%x}_eta {%x}_eta(1) = 0.5 {%x}_eta(2) = 0.05 {%x}_eta(3) = 0.9 ' use var-cov of sample in "s0" as starting value of variance-covariance matrix series {%x}_var_e = @var({%x}_e) series {%x}_var_s = @var({%x}_s) series {%x}_z_e = {%x}_e/@sqrt(@var({%x}_e)) series {%x}_z_s = {%x}_s/@sqrt(@var({%x}_s)) series {%x}_xi = -log((1-@cor({%x}_e,{%x}_s))/(1+@cor({%x}_e,{%x}_s))) series {%x}_cor=2/(1+@exp(-{%x}_xi))-1 series {%x}_cov={%x}_cor*@sqrt(@var({%x}_e)*@var({%x}_s)) scalar E_z=@sqrt(2/@acos(-1)) ' ........................................................... ' LOG LIKELIHOOD ' set up the likelihood ' 1) open a new blank likelihood object (L.O.) name bvegarch ' 2) specify the log likelihood model by append ' ........................................................... logl {%x}_bvegarch {%x}_bvegarch.append @logl logl {%x}_bvegarch.append {%x}_e = E_{%x} - ({%x}_alpha0(1) + {%x}_alpha1(1)*E_{%x}(-1) + {%x}_alpha2(1)*E_{%x}(-2) + {%x}_alpha3(1)*E_{%x}(-3) + {%x}_alpha4(1)*E_{%x}(-4) + {%x}_alpha1(2)*S_{%x}(-1) + {%x}_alpha2(2)*S_{%x}(-2) + {%x}_alpha3(2)*S_{%x}(-3) + {%x}_alpha4(2)*S_{%x}(-4)) {%x}_bvegarch.append {%x}_s = S_{%x} - ({%x}_alpha0(2) + {%x}_alpha1(3)*E_{%x}(-1) + {%x}_alpha2(3)*E_{%x}(-2) + {%x}_alpha3(3)*E_{%x}(-3) + {%x}_alpha4(3)*E_{%x}(-4) + {%x}_alpha1(4)*S_{%x}(-1) + {%x}_alpha2(4)*S_{%x}(-2) + {%x}_alpha3(4)*S_{%x}(-3) + {%x}_alpha4(4)*S_{%x}(-4)) {%x}_bvegarch.append {%x}_z_e = {%x}_e/@sqrt(@var({%x}_e)) {%x}_bvegarch.append {%x}_z_s = {%x}_s/@sqrt(@var({%x}_s)) ' calculate the variance and covariance series {%x}_bvegarch.append log({%x}_var_e) = {%x}_beta0(1) + {%x}_beta1(1)*(abs({%x}_z_e(-1))-E_z+{%x}_delta(1)*{%x}_z_e(-1)) + {%x}_beta1(2)*(abs({%x}_z_s(-1))-E_z+{%x}_delta(2)*{%x}_z_s(-1)) + {%x}_gamma1(1)*log({%x}_var_e(-1)) + {%x}_gamma2(1)*log({%x}_var_e(-2)) {%x}_bvegarch.append log({%x}_var_s) = {%x}_beta0(2) + {%x}_beta1(3)*(abs({%x}_z_e(-1))-E_z+{%x}_delta(1)*{%x}_z_e(-1)) + {%x}_beta1(4)*(abs({%x}_z_s(-1))-E_z+{%x}_delta(2)*{%x}_z_s(-1)) + {%x}_gamma1(2)*log({%x}_var_s(-1)) + {%x}_gamma2(2)*log({%x}_var_s(-2)) {%x}_bvegarch.append {%x}_z_e = {%x}_e/@sqrt({%x}_var_e) {%x}_bvegarch.append {%x}_z_s = {%x}_s/@sqrt({%x}_var_s) {%x}_bvegarch.append {%x}_xi = {%x}_eta(1) + {%x}_eta(2)*{%x}_z_e(-1)*{%x}_z_s(-1) + {%x}_eta(3)*{%x}_xi(-1) {%x}_bvegarch.append {%x}_cor=2/(1+@exp(-{%x}_xi))-1 {%x}_bvegarch.append {%x}_cov={%x}_cor*@sqrt({%x}_var_e*{%x}_var_s) ' determinant of the variance-covariance matrix {%x}_bvegarch.append {%x}_deth = {%x}_var_e*{%x}_var_s - {%x}_cov^2 ' log-likelihood series {%x}_bvegarch.append logl =-0.5*(2*1*(660-!p)*log(2*@acos(-1)) + log({%x}_deth) + ({%x}_e^2*{%x}_var_s + {%x}_s^2*{%x}_var_e - 2*{%x}_cov*{%x}_e*{%x}_s)/{%x}_deth) ' estimate the model smpl s1 {%x}_bvegarch.ml(showopts, m=500, c=1e-6) ' change below to display different output show {%x}_bvegarch.output graph {%x}_vare.line {%x}_var_e graph {%x}_vars.line {%x}_var_s graph {%x}_coves.line {%x}_cov graph {%x}_cores.line {%x}_cor show {%x}_vare show {%x}_vars show {%x}_coves show {%x}_cores

Re: Bivariate EGARCH with Panel Data

Posted: Fri Sep 09, 2011 1:12 am
by jma42
Btw, I am using EViews 6, if this makes any difference.

Re: Bivariate EGARCH with Panel Data

Posted: Fri Sep 09, 2011 4:10 pm
by jma42
I found the problem myself. The OLS estimator simply made the conditional variance series move too wildly. So I changed the starting value of the coefficients to one of the individuals' estimation result and eliminated some of the outliers in the data (I have 17 countries in the panel. Outliers are inevitable.) The programme is working perfectly now. Thanx to anyone who was looking.

Now I only need to integrate the cross-sectional correlation into the log likelihood estimation, then I am sweet. I am so happy about the result coz the estimation was the biggest uncertainty of my research project. Hooooooooooooraaaaaaaaaaaaaaaaaaaayyyyyyyyyyyyyyy:D
I think EViews developers should consider adding the ARCH estimation as one of the options for panel data. It's getting more and more popular now.

Re: Bivariate EGARCH with Panel Data

Posted: Mon Sep 12, 2011 9:50 am
by EViews Glenn
Do you have references? The question is what sorts of panel structures people want to permit...

Re: Bivariate EGARCH with Panel Data

Posted: Mon Sep 12, 2011 4:38 pm
by jma42
For example, PP-GARCH
Cermeño, R., Grier, K.B., 2006. Conditional heteroskedasticity and cross-sectional dependence in panel data: an empirical study of inflation uncertainty in the G7 countries. In: Baltagi, B.H. (Ed.), Panel Data Econometrics, vol. 10. Elsevier, New York, pp. 259–278. Chapter

Re: Bivariate EGARCH with Panel Data

Posted: Mon Sep 12, 2011 4:58 pm
by EViews Glenn
That's useful. Pretty straightforward extension, though I'm not certain that the variance specification is one that everyone would want to adopt. I'd ideally like to see a broader range of papers than one empirical application, but this is a useful start in thinking about the problem and how to proceed. Any other references that come to mind, let us know.

Re: Bivariate EGARCH with Panel Data

Posted: Wed Sep 14, 2011 9:21 pm
by jma42
There are a number of other papers adopted Panel GARCH. For example:

Svirydzenka (2010) The Role of the International Investor Mix in the Stock Market Stability
Lee (2009) The link between output growth and volatility: Evidence from a GARCH model with panel data
Curado and Rocha () INFLATION TARGETING AND EXCHANGE RATE VOLATILITY: A PANEL E-GARCH ANALYSIS

I have a question here. When the dimension of variance-covariance matrix (H) is very high, it is almost impossible to write the score function (e'(1/H)e) of the log likelihood function in a plain polynomial form since it's to hard to write the inverse form of H. Is there a way to get around this problem? For instance, can I make a matrix vary with time and use @PINVERSE?

Re: Bivariate EGARCH with Panel Data

Posted: Thu Sep 15, 2011 9:42 am
by EViews Glenn
Unfortunately, not in the LOGL object...

Thanks for the references...

Re: Bivariate EGARCH with Panel Data

Posted: Thu Nov 01, 2012 3:40 am
by Kavorka
Nice job!

It would be interesting to see the finished program, where e.g. the cross-sectional correlation is included into the log likelihood estimation.

Re: Bivariate EGARCH with Panel Data

Posted: Sat Jun 21, 2014 7:28 am
by Fathi
It would be much better if you give us the final complete code. Thanks for the share.

Fathi