Spillover index (Diebold&Yilmaz,2011) using SVAR

Questions and discussions on Vector Autoregressions
Fisher
Posts: 6
Joined: Tue Apr 21, 2015 7:32 pm

Spillover index (Diebold&Yilmaz,2011) using SVAR

Unread post by Fisher »

Dear Tom;
I modify the replication RATS codes of Diebold and Yilmaz (2009, 2011) to extract the rolling spillover index (from others, to others, and the net spillover) using Structural Decomposition, but fail to gauge the results. Could you look at the codes and tell me why? Furthermore, if I constrain the error decomposition using the A-matrix estimated over the whole sample while calculate the rolling spillover indices, could you tell me how to?

The Code and Data are attached below:

Code: Select all

*
*
compute usegirf=0
*
OPEN DATA "C:\Users\irsyz\Dropbox\FR_JY03.xls"
CALENDAR(D) 1995:1:2
DATA(FORMAT=XLS,ORG=COLUMNS) 1995:01:02 2000:12:29 X1 X2 X3 X4 X5 X6 DX1 DX2 DX3 DX4 DX5 DX6
*
@varlagselect(lags=15,crit=aic)
# X1 X2 X3 X4 X5 X6
*
compute nlags=8
*
system(model=varmodel)
variables DX1 DX2 DX3 DX4  DX5 DX6
lags 1 to nlags
det constant
end(system)
*
estimate(noprint)
*
nonlin(parmset=svar) a21 a25 a26 a31 a34 a42 a65
*
dec frml[rect] afrml
frml afrml = ||1.0,0.0,0.0,0.0,0.0,0.0|$
               	   a21,1.0,0.0,0.0,a25,a26|$
                   a31,0.0,1.0,a34,0.0,0.0|$
                   0.0,a42,0.0,1.0,0.0,0.0|$
                   0.0,0.0,0.0,0.0,1.0,0.0|$
                   0.0,0.0,0.0,0.0,a65,1.0||
*
compute a21=a25=a26=a31=a34=a42=a65=0.0
*
cvmodel(a=afrml,parmset=svar,method=bfgs,factor=fsvar) %sigma
*
compute shocklabels=||"SHA","SHB","SZA","SZB","HKH","HKR"||
compute varlabels=||"SHA","SHB","SZA","SZB","HKH","HKR"||
*
*errors(model=varmodel,steps=30,labels=shocklabels,factor=fsvar)
*
*
compute rstart=%regstart(),rend=%regend()
*
* Analyze the 3 step responses
*
compute nsteps=3
*********************************************************************
*
* Produce the appropriate "factor" matrix from structural decomposition
*
function FactorMatrix
type rect FactorMatrix
if usegirf
   compute FactorMatrix=%sigma*inv(%diag(%sqrt(%xdiag(%sigma))))
else
   compute FactorMatrix=fsvar
end
*********************************************************************
*
compute gfactor=FactorMatrix()
*
errors(model=varmodel,steps=nsteps,factor=gfactor,stderrs=gstderrs,noprint,results=gfevd)
compute gfevdx=%xt(gfevd,nsteps)
*
* 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
*
* Rolling window analysis
*
compute nspan=200
dec vect[series] rfrom(%nvar) rto(%nvar)
*
do end=rstart+nspan-1,rend
   estimate(model=varmodel,noprint) end-nspan+1 end
   cvmodel(a=afrml,parmset=svar,method=bfgs,factor=fsvar,iterations=1000,noprint) %sigma
   compute gfactor=FactorMatrix()
   errors(model=varmodel,steps=nsteps,factor=gfactor,stderrs=gstderrs,noprint,results=gfevd)
   compute gfevdx=%xt(gfevd,nsteps)
   ewise fromvar(i)=%sum(%xrow(gfevdx,i))-gfevdx(i,i)
   ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
   compute %pt(rfrom,end,fromvar)
   compute %pt(rto,end,tovar)
end do end
*
*Compute net spillover for each city
*
set SHAf  = 100.0*rfrom(1)
set SHAt  = 100.0*rto(1)
set SHAn = 100.0*(rto(1) - rfrom(1))
set SHBf  = 100.0*rfrom(2)
set SHBt  = 100.0*rto(2)
set SHBn = 100.0*(rto(2) - rfrom(2))
set SZAf  = 100.0*rfrom(3)
set SZAt  = 100.0*rto(3)
set SZAn = 100.0*(rto(3) - rfrom(3))
set SZBf  = 100.0*rfrom(4)
set SZBt  = 100.0*rto(4)
set SZBn = 100.0*(rto(4) - rfrom(4))
set HKHf  = 100.0*rfrom(5)
set HKHt  = 100.0*rto(5)
set HKHn = 100.0*(rto(5) - rfrom(5))
set HKRf  = 100.0*rfrom(6)
set HKRt  = 100.0*rto(6)
set HKRn = 100.0*(rto(6) - rfrom(6))

Best wishes
Ziliang
Attachments
FR03Rolling.RPF
The Codes
(3.2 KiB) Downloaded 859 times
FR_JY03.xls
The data
(425.5 KiB) Downloaded 792 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spillover index (Diebold&Yilmaz,2011) using SVAR

Unread post by TomDoan »

The fix is to move

compute rstart=%regstart(),rend=%regend()

up after the original ESTIMATE. The CVMODEL is also an estimation instruction (which wasn't present in the original D&Y program) and it resets that.

However
  1. Your overidentifying restrictions are rather strongly rejected, so you might want to think about that.
  2. I'm not sure how the "spillover" idea applies here. The point in both the D&Y papers is to use "factors" that directly associate shocks with variables which is how you get the spillover from (say) country A to country B. With an SVAR, the shocks are structural shocks that aren't (in general) associated with any specific variable.
Fisher
Posts: 6
Joined: Tue Apr 21, 2015 7:32 pm

Re: Spillover index (Diebold&Yilmaz,2011) using SVAR

Unread post by Fisher »

Dear Tom;
Many thanks for your reply. Actually, I want to calculate (say X1, X2, and X3) the portion of X1 can be explained by X2 and X3 at the Structural decomposition at step K (from others), and the portion that X1 contributes to X2 and X3 at the decomposition of step K (to others). Then, similar to Diebold and Yilmaz (2011), the net influence may be gauged as the difference of "to others" and "from others".

To further check this from time-varying perspective, I want to adapt the RATS replication codes and calculate the above "from others", ''to others" with a fixed rolling window (span=200). Meanwhile, I want to restrain the estimated A-matrix unchangeable, while only updating the VAR coefficients and %sigma. In my opinion, though I may need to rethink the "spillover" explanation, the calculation process resemble that of Diebold and Yilmaz (2009,2011). The only difference is that I use the structural decomposition, instead of generalized (or Cholesky).

I revise the loop codes as follows, without re-estimate the A-matrix using CVMODEL. Though it not reports any error, all the calculated series are empty with no observations. Could you tell me why?

Code: Select all

*Rolling Analysis
compute rstart=%regstart(),rend=%regend()
*
* Analyze the 3 step responses
*
compute nsteps=3
*********************************************************************
*
* Produce the appropriate "factor" matrix from structural decomposition
*
function FactorMatrix
type rect FactorMatrix
compute FactorMatrix=fsvar
*********************************************************************
*
compute gfactor=FactorMatrix()
*
errors(model=varmodel,steps=nsteps,factor=gfactor,stderrs=gstderrs,noprint,results=gfevd)
compute gfevdx=%xt(gfevd,nsteps)
*
* 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
*
* Rolling window analysis
*
compute nspan=200
dec vect[series] rfrom(%nvar) rto(%nvar)
*
do end=rstart+nspan-1,rend
   estimate(model=varmodel,noprint) end-nspan+1 end
   compute gfactor=FactorMatrix()
   errors(model=varmodel,steps=nsteps,factor=gfactor,stderrs=gstderrs,noprint,results=gfevd)
   compute gfevdx=%xt(gfevd,nsteps)
   ewise fromvar(i)=%sum(%xrow(gfevdx,i))-gfevdx(i,i)
   ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
   compute %pt(rfrom,end,fromvar)
   compute %pt(rto,end,tovar)
end do end
the results:
results.jpg
results.jpg (147.15 KiB) Viewed 8977 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spillover index (Diebold&Yilmaz,2011) using SVAR

Unread post by TomDoan »

I told you why---you have the compute RSTART and REND in the wrong place. You didn't get rid of the incorrect one that's the first line in the code snip that you posted.

But the point remains that in a structural model, the shocks aren't "X1", "X2" and "X3" so the "from others" and "to others" labels don't make sense.
Fisher
Posts: 6
Joined: Tue Apr 21, 2015 7:32 pm

Re: Spillover index (Diebold&Yilmaz,2011) using SVAR

Unread post by Fisher »

TomDoan wrote:I told you why---you have the compute RSTART and REND in the wrong place. You didn't get rid of the incorrect one that's the first line in the code snip that you posted.

But the point remains that in a structural model, the shocks aren't "X1", "X2" and "X3" so the "from others" and "to others" labels don't make sense.
Many thanks for your generous help. I've corrected the mistakes. Sorry for not catching the point previously. I'm a beginner for both RATS and English writing. Hope to get much better for both RATS coding and English writing next time.

Thanks again.

Best Wishes
Ziliang
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spillover index (Diebold&Yilmaz,2011) using SVAR

Unread post by TomDoan »

As noted above, you probably want to fix your structural model so it fits better.

There's nothing wrong with doing a regular FEVD with a structural model over moving windows. It's just that there's no real point in aggregating the effects of shocks the way D&Y do it when the shocks don't correspond 1-1 with the variables.
Post Reply