Generalized Variance Decomposition with Constraints
Posted: Wed Sep 19, 2012 10:07 am
To Whom It May Concern,
I am trying to estimate generalized variance decompositions for a 7-variable VAR model, using the code replicating Diebold-Yilmaz EJ 2009 (http://www.estima.com/forum/viewtopic.p ... old+yilmaz).
The thing is that I need to put constraints on some of the coefficients in the equations, so that some variables (R_KEN, R_TZA, R_UGA, R_RWA, R_BDI) do not affect the other (R_USA, R_EUR).
I used %modelsetcoeffs and wrote the program pasted below; however, it seems not working.
The estimated decompositions only slightly differ from those without restrictions, and they do not conform to my expectation that variables with zero coefficients provide zero spillovers to the others.
When I try a simpler program using Cholesky decomposition (also pasted below), it gives me an expected result: zero spillover from variables with restrictions to the others.
I suppose it might be because calculated factor matrix (FactorMatrix) does not reflect the restrictions imposed.
But I could not figure out how I can deal with this.
Any help will be greatly appreciated. Thank you so much.
Best,
Masafumi
Simple program with/without constraints
I am trying to estimate generalized variance decompositions for a 7-variable VAR model, using the code replicating Diebold-Yilmaz EJ 2009 (http://www.estima.com/forum/viewtopic.p ... old+yilmaz).
The thing is that I need to put constraints on some of the coefficients in the equations, so that some variables (R_KEN, R_TZA, R_UGA, R_RWA, R_BDI) do not affect the other (R_USA, R_EUR).
I used %modelsetcoeffs and wrote the program pasted below; however, it seems not working.
The estimated decompositions only slightly differ from those without restrictions, and they do not conform to my expectation that variables with zero coefficients provide zero spillovers to the others.
When I try a simpler program using Cholesky decomposition (also pasted below), it gives me an expected result: zero spillover from variables with restrictions to the others.
I suppose it might be because calculated factor matrix (FactorMatrix) does not reflect the restrictions imposed.
But I could not figure out how I can deal with this.
Any help will be greatly appreciated. Thank you so much.
Best,
Masafumi
Code: Select all
*
* Replication file for Diebold and Yilmaz(2009), "Measuring Financial
* Asset Return and Volatility Spillovers, with Application to Global
* Equity Markets," Economic Journal, vol. 119, no. 534, 158-171.
*
* Analysis of returns data
*
* If you make usegirf=1, this will use the generalized spillover
* measures proposed in Diebold and Yilmaz(2011), "Better to Give than to
* Receive: Predictive Directional Measurement of Volatility Spillovers",
* IJF, to appear. usegirf=0 does the Choleski factorization used in the
* 2009 paper.
*
compute usegirf=1
*
OPEN DATA NEER_EAC.XLS
CALENDAR(W) 2000:1:9
DATA(FORMAT=XLS,ORG=COLUMNS,LEFT=2,DATEFORM="m/d/y") 2000:01:09 2012:09:09 R_USA R_EUR R_KEN R_TZA R_UGA $
R_RWA R_BDI
*
dec vect[int] returns
enter(varying) returns
# R_USA R_EUR R_KEN R_TZA R_UGA R_RWA R_BDI
dec vect[string] longlabels(%size(returns))
enter longlabels
# "U.S. Dollar" "Euro" "Kenya Shilling" "Tanzania Shilling" "Uganda Shilling" "Rwanda Franc" "Burundi Franc"
dec vect[string] shortlabels(%size(returns))
enter shortlabels
# "USA" "EUR" "KEN" "TZA" "UGA" "RWA" "BDI"
*
* Setup and estimate one lag VAR
*
system(model=returnvar)
variables returns
lags 1
det constant
end(system)
*
estimate
compute coeffs = %modelgetcoeffs(returnvar)
compute coeffs(3,1) = 0
compute coeffs(4,1) = 0
compute coeffs(5,1) = 0
compute coeffs(6,1) = 0
compute coeffs(7,1) = 0
compute coeffs(3,2) = 0
compute coeffs(4,2) = 0
compute coeffs(5,2) = 0
compute coeffs(6,2) = 0
compute coeffs(7,2) = 0
compute %modelsetcoeffs(returnvar, coeffs)
*
* Save the full estimation range for later use
*
compute rstart=%regstart(),rend=%regend()
*
* Compute variance decompositions up to 10 step and analyze the 4 step responses
*
compute nsteps=10
compute asteps=4
*********************************************************************
*
* Produce the appropriate "factor" matrix from %sigma
*
function FactorMatrix
type rect FactorMatrix
if usegirf
compute FactorMatrix=%sigma*inv(%diag(%sqrt(%xdiag(%sigma))))
else
compute FactorMatrix=%decomp(%sigma)
end
*********************************************************************
*
compute gfactor=FactorMatrix()
*
errors(model=returnvar,steps=nsteps,factor=gfactor,stderrs=gstderrs,results=gfevd)
compute gfevdx=%xt(gfevd,asteps)
display "4-Step-Ahead Variance Decomposition" gfevdx
*
* These are for computing the contributions from others, to others and
* to others including own for each variable.
*
dec vect tovar(%nvar) fromvar(%nvar) tototal(%nvar)
ewise fromvar(i)=%sum(%xrow(gfevdx,i))-gfevdx(i,i)
ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
ewise tototal(i)=tovar(i)+1-fromvar(i)
compute spillover=100.0*%sum(tovar)/%nvar
*
report(action=define,title="Table [ ]. Spillover Table for EAC Currency Returns")
report(atrow=1,atcol=2,align=center,fillby=rows) shortlabels
report(atrow=2,atcol=1,fillby=cols) shortlabels
report(atrow=2,atcol=2) 100.0*gfevdx
report(atrow=%nvar+2,atcol=1,fillby=rows) "Contribution to others" 100.0*tovar
report(atrow=%nvar+3,atcol=1,fillby=rows) "Contribution including own" 100.0*tototal
report(atcol=%nvar+2,atrow=1) "From Others"
report(atcol=%nvar+2,atrow=2,fillby=cols) 100.0*fromvar
report(atrow=%nvar+2,atcol=%nvar+2,fillby=cols) 100.0*%sum(tovar)
report(atrow=%nvar+3,atcol=%nvar+2,align=right) %strval(spillover,"##.#")+"%"
report(atrow=2,atcol=2,torow=%nvar+3,tocol=%nvar+2,action=format,picture="*.#")
report(action=show)
*
* Rolling window analysis
*
compute nspan=200
set spillreturns rstart+nspan-1 rend = 0.0
set from1to1 rstart+nspan-1 rend = 0.0
set from2to1 rstart+nspan-1 rend = 0.0
set from3to1 rstart+nspan-1 rend = 0.0
set from4to1 rstart+nspan-1 rend = 0.0
set from5to1 rstart+nspan-1 rend = 0.0
set from6to1 rstart+nspan-1 rend = 0.0
set from7to1 rstart+nspan-1 rend = 0.0
set from1to2 rstart+nspan-1 rend = 0.0
set from2to2 rstart+nspan-1 rend = 0.0
set from3to2 rstart+nspan-1 rend = 0.0
set from4to2 rstart+nspan-1 rend = 0.0
set from5to2 rstart+nspan-1 rend = 0.0
set from6to2 rstart+nspan-1 rend = 0.0
set from7to2 rstart+nspan-1 rend = 0.0
set from1to3 rstart+nspan-1 rend = 0.0
set from2to3 rstart+nspan-1 rend = 0.0
set from3to3 rstart+nspan-1 rend = 0.0
set from4to3 rstart+nspan-1 rend = 0.0
set from5to3 rstart+nspan-1 rend = 0.0
set from6to3 rstart+nspan-1 rend = 0.0
set from7to3 rstart+nspan-1 rend = 0.0
set from1to4 rstart+nspan-1 rend = 0.0
set from2to4 rstart+nspan-1 rend = 0.0
set from3to4 rstart+nspan-1 rend = 0.0
set from4to4 rstart+nspan-1 rend = 0.0
set from5to4 rstart+nspan-1 rend = 0.0
set from6to4 rstart+nspan-1 rend = 0.0
set from7to4 rstart+nspan-1 rend = 0.0
set from1to5 rstart+nspan-1 rend = 0.0
set from2to5 rstart+nspan-1 rend = 0.0
set from3to5 rstart+nspan-1 rend = 0.0
set from4to5 rstart+nspan-1 rend = 0.0
set from5to5 rstart+nspan-1 rend = 0.0
set from6to5 rstart+nspan-1 rend = 0.0
set from7to5 rstart+nspan-1 rend = 0.0
set from1to6 rstart+nspan-1 rend = 0.0
set from2to6 rstart+nspan-1 rend = 0.0
set from3to6 rstart+nspan-1 rend = 0.0
set from4to6 rstart+nspan-1 rend = 0.0
set from5to6 rstart+nspan-1 rend = 0.0
set from6to6 rstart+nspan-1 rend = 0.0
set from7to6 rstart+nspan-1 rend = 0.0
set from1to7 rstart+nspan-1 rend = 0.0
set from2to7 rstart+nspan-1 rend = 0.0
set from3to7 rstart+nspan-1 rend = 0.0
set from4to7 rstart+nspan-1 rend = 0.0
set from5to7 rstart+nspan-1 rend = 0.0
set from6to7 rstart+nspan-1 rend = 0.0
set from7to7 rstart+nspan-1 rend = 0.0
do end=rstart+nspan-1,rend
estimate(noprint) end-nspan+1 end
*
* Skip any data points where the rolling VAR has an explosive root.
*
eigen(cvalues=cv) %modelcompanion(returnvar)
if %cabs(cv(1))>=1.0 {
compute spillreturns(end)=%na
next
}
compute gfactor=FactorMatrix()
errors(model=returnvar,steps=nsteps,factor=gfactor,stderrs=gstderrs,noprint,results=gfevd)
compute gfevdx=%xt(gfevd,asteps)
ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
compute spillreturns(end)=100.0*%sum(tovar)/%nvar
compute from1to1(end)=gfevdx(1,1)*100
compute from2to1(end)=gfevdx(1,2)*100
compute from3to1(end)=gfevdx(1,3)*100
compute from4to1(end)=gfevdx(1,4)*100
compute from5to1(end)=gfevdx(1,5)*100
compute from6to1(end)=gfevdx(1,6)*100
compute from7to1(end)=gfevdx(1,7)*100
compute from1to2(end)=gfevdx(2,1)*100
compute from2to2(end)=gfevdx(2,2)*100
compute from3to2(end)=gfevdx(2,3)*100
compute from4to2(end)=gfevdx(2,4)*100
compute from5to2(end)=gfevdx(2,5)*100
compute from6to2(end)=gfevdx(2,6)*100
compute from7to2(end)=gfevdx(2,7)*100
compute from1to3(end)=gfevdx(3,1)*100
compute from2to3(end)=gfevdx(3,2)*100
compute from3to3(end)=gfevdx(3,3)*100
compute from4to3(end)=gfevdx(3,4)*100
compute from5to3(end)=gfevdx(3,5)*100
compute from6to3(end)=gfevdx(3,6)*100
compute from7to3(end)=gfevdx(3,7)*100
compute from1to4(end)=gfevdx(4,1)*100
compute from2to4(end)=gfevdx(4,2)*100
compute from3to4(end)=gfevdx(4,3)*100
compute from4to4(end)=gfevdx(4,4)*100
compute from5to4(end)=gfevdx(4,5)*100
compute from6to4(end)=gfevdx(4,6)*100
compute from7to4(end)=gfevdx(4,7)*100
compute from1to5(end)=gfevdx(5,1)*100
compute from2to5(end)=gfevdx(5,2)*100
compute from3to5(end)=gfevdx(5,3)*100
compute from4to5(end)=gfevdx(5,4)*100
compute from5to5(end)=gfevdx(5,5)*100
compute from6to5(end)=gfevdx(5,6)*100
compute from7to5(end)=gfevdx(5,7)*100
compute from1to6(end)=gfevdx(6,1)*100
compute from2to6(end)=gfevdx(6,2)*100
compute from3to6(end)=gfevdx(6,3)*100
compute from4to6(end)=gfevdx(6,4)*100
compute from5to6(end)=gfevdx(6,5)*100
compute from6to6(end)=gfevdx(6,6)*100
compute from7to6(end)=gfevdx(6,7)*100
compute from1to7(end)=gfevdx(7,1)*100
compute from2to7(end)=gfevdx(7,2)*100
compute from3to7(end)=gfevdx(7,3)*100
compute from4to7(end)=gfevdx(7,4)*100
compute from5to7(end)=gfevdx(7,5)*100
compute from6to7(end)=gfevdx(7,6)*100
compute from7to7(end)=gfevdx(7,7)*100
end do end
graph(footer="Spillover plot. Returns. 200 week window. 4 step horizon")
# spillreturns
open copy VD_EAC.xls
copy(dates,format=xls,org=columns)
Code: Select all
OPEN DATA NEER_EAC.XLS
CALENDAR(W) 2000:1:9
DATA(FORMAT=XLS,ORG=COLUMNS,LEFT=2,DATEFORM="m/d/y") 2000:01:09 2012:09:09 R_USA R_EUR R_KEN R_TZA R_UGA $
R_RWA R_BDI
* --------------------------------------------------------------------------
* Without Restrictions on Coefficients
* --------------------------------------------------------------------------
dec vect[int] returns
enter(varying) returns
# R_USA R_EUR R_KEN R_TZA R_UGA R_RWA R_BDI
* Setup and estimate one lag VAR
system(model=returnvar)
variables returns
lags 1
det constant
end(system)
estimate
* Compute variance decompositions up to 10 step and analyze the 4 step responses
errors(model=returnvar,steps=10,cv=%sigma,stderrs=gstderrs1,results=gfevd1)
compute gfevdx1=%xt(gfevd1,4)
display "4-Step-Ahead Variance Decomposition" gfevdx1
* --------------------------------------------------------------------------
* Coefficients Restricted
* --------------------------------------------------------------------------
compute coeffs = %modelgetcoeffs(returnvar)
compute coeffs(3,1) = 0
compute coeffs(4,1) = 0
compute coeffs(5,1) = 0
compute coeffs(6,1) = 0
compute coeffs(7,1) = 0
compute coeffs(3,2) = 0
compute coeffs(4,2) = 0
compute coeffs(5,2) = 0
compute coeffs(6,2) = 0
compute coeffs(7,2) = 0
compute %modelsetcoeffs(returnvar, coeffs)
* Compute variance decompositions up to 10 step and analyze the 4 step responses
errors(model=returnvar,steps=10,cv=%sigma,stderrs=gstderrs2,results=gfevd2)
compute gfevdx2=%xt(gfevd2,4)
display "4-Step-Ahead Variance Decomposition" gfevdx2