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
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
