Page 1 of 1

Variance Decomposition

Posted: Tue Sep 23, 2014 3:20 pm
by HypatiaCU
Hi,

I am working on variance decomposition of a simple triangular VAR with 1 lag.
[y1_t,y2_t]'=A*[y1_{t-1},y2_{t-1}]'+[error1, erro2]'.
I know how to do the standard variance decomposition. But what I am interested in is a variable
x_t = y2_t - y1_t + y1_{t-1}
How to do the variance decomposition of x_{t+h} for h=10 periods? I know how to compute this step by step in Matlab. Is there a function in Rats that could give me the result directly?

Thank you very much,
Hypatia

Re: Variance Decomposition

Posted: Tue Sep 23, 2014 3:50 pm
by TomDoan
Add the definitional identity for X:

equation(identity,coeffs=||1.0,-1.0,1.0||) xdef x
# y2 y1{0 1}

and do

ERRORS(model=mymodel+xdef,other options)

where mymodel is your VAR. The Makridakis, et al example mwhp423.rpf does something similar.

Re: Variance Decomposition

Posted: Mon Sep 29, 2014 10:37 am
by HypatiaCU
Thanks a lot.
When I do ERRORS(model=mymodel+xdef, STEPS=10), it seems the variance decomposition result of y1 and y2 are changed. They are not the same as the result from ERRORS(model=mymodel, STEPS=10). Why?

Re: Variance Decomposition

Posted: Mon Sep 29, 2014 10:49 am
by TomDoan
Add the option CV=%SIGMA to the ERRORS instruction. It looks like the covariance matrix doesn't copy through when you do the + on the model.

Re: Variance Decomposition

Posted: Thu Feb 11, 2016 9:17 am
by cczzwhy
Hello,Tom!
I want to ask about how to do the variance decomposition for a recursive var via cholesky factorization?
I run the code ERRORS(model=mymodel, factor=f,other options),but the result is different each time.

Re: Variance Decomposition

Posted: Thu Feb 11, 2016 5:09 pm
by TomDoan
"each time" what? What's the F matrix that you're using in the FACTOR option?

Re: Variance Decomposition

Posted: Tue Feb 16, 2016 1:21 am
by cczzwhy
I revised a mistake and this is the code using now,I am not sure if it is OK...

Code: Select all

system(model=varmodel)
var y1 y2 y3 y4 x1
lags 1 to 4
det constant
end(system)
estimate(resids=resids)
compute vsigma=%sigma

compute f=%decomp(vsigma)
compute fd=%xdiag(f)
ewise f(i,j)=f(i,j)/fd(j)
impulse(steps=nstep,model=varmodel,responses=responsefirst,factor=f,noprint)
errors(model=varmodel,steps=nstep,factor=f)

Re: Variance Decomposition

Posted: Tue Feb 16, 2016 6:28 am
by TomDoan
That would give you impulse responses to Cholesky shocks standardized to unit impacts. However, because F is no longer a factor of the covariance matrix, the ERRORS is not computing a decomposition of variance.

Re: Variance Decomposition

Posted: Thu Feb 18, 2016 6:07 am
by cczzwhy
I have no idea about how to generate the variance decompositon,should I use errors(model=varmodel,steps=nstep,factor=swish)?

Code: Select all

*1. Cholesky factorizations
*
compute f=%decomp(vsigma)
compute fd=%xdiag(f)
ewise f(i,j)=f(i,j)/fd(j)
impulse(steps=nstep,model=varmodel,responses=responsefirst,factor=f)

compute swish=%decomp(%sigma)
******************************************************************
estimate
compute nvar   =%nvar
compute fxx    =%decomp(%xx)
compute fwish  =%decomp(inv(%nobs*%sigma))
compute wishdof=%nobs-%nreg
compute betaols=%modelgetcoeffs(varmodel)
*
*
declare vect[rect] %%responses(ndraws)
declare rect[series] impulses(nvar,nvar)

infobox(action=define,progress,lower=1,upper=ndraws) "Monte Carlo Integration"
do draw=1,ndraws
   if %clock(draw,2)==1 {
      compute sigmad  =%ranwisharti(fwish,wishdof)
      compute fsigma  =%decomp(sigmad)
      compute betau   =%ranmvkron(fsigma,fxx)
      compute betadraw=betaols+betau
   }
   else
      compute betadraw=betaols-betau
   *
   * Push the draw for the coefficient back into the model.
   *
   compute %modelsetcoeffs(varmodel,betadraw)
   impulse(noprint,model=varmodel,factor=fsigma,$
     results=impulses,steps=nstep)
   *
   * Save the impulse responses
	*
   dim %%responses(draw)(nvar*nvar,nstep)
   ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
   infobox(current=draw)
end do draw
infobox(action=remove)

Re: Variance Decomposition

Posted: Thu Feb 18, 2016 7:43 am
by TomDoan
Outside the loop, it would need to be FACTOR=%DECOMP(VSIGMA). You can change the scales on impulse responses (which is done here to give unit impacts), but to do a FEVD, you need a factor of the actual covariance matrix.

Re: Variance Decomposition

Posted: Sun Jun 19, 2016 7:34 am
by cczzwhy
Hello Tom!How Can I compute a variance decomposition for two series in a linear regression(y dependent variable,x independent variable) as in a VAR system?Thanks in advance!

Re: Variance Decomposition

Posted: Sun Jun 19, 2016 11:00 am
by TomDoan
You can't. You need a full dynamic model.

Re: Variance Decomposition

Posted: Mon Jun 20, 2016 5:24 am
by cczzwhy
Is it possible for transform two correlated series into uncorrelated by doing cholesky decomposition?

Re: Variance Decomposition

Posted: Mon Jun 20, 2016 7:52 am
by TomDoan
The inverse of any factor (Cholesky or not) of a covariance matrix can be used to transform a pair of series to a pair of theoretically uncorrelated series. If S is the covariance matrix of the series pair(x,y), then

compute ifac=inv(%decomp(s))
set ytilde = ifac(2,1)*x+ifac(2,2)*y

create ytilde that would have a zero correlation with x.