Shock in exogenous variables in a SVAR
Re: Shock in exogenous variables in a SVAR
There's almost certainly something wrong with the signs on this:
equation(coeffs=||1.0,0.3,0.3,0.3||) ect1
# loggdp loginv logc ftb3
which is saying that the equilibrium condition is Y+.3I+.3C+.3R
To get both dftb3 and ftb3 in the model with the proper relationship, you need to include an identity:
equation(coeffs=||1.0,-1.0||,identity) dratedef dftb3
# ftb3{0 1}
then add DRATEDEF to your model option.
equation(coeffs=||1.0,0.3,0.3,0.3||) ect1
# loggdp loginv logc ftb3
which is saying that the equilibrium condition is Y+.3I+.3C+.3R
To get both dftb3 and ftb3 in the model with the proper relationship, you need to include an identity:
equation(coeffs=||1.0,-1.0||,identity) dratedef dftb3
# ftb3{0 1}
then add DRATEDEF to your model option.
Re: Shock in exogenous variables in a SVAR
You are right the equilibrium relationship seems odd to say the least. I was just focusing on the coding side. Thank you !
impulse(noprint,model=%modelsubstect(vecmmodel)+rateeq+dratedef, factor=%identity(4), shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
is finally giving me what I want
impulse(noprint,model=%modelsubstect(vecmmodel)+rateeq+dratedef, factor=%identity(4), shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
is finally giving me what I want
Re: Shock in exogenous variables in a SVAR
How can I modify the following code that Tom posted to accumulate impulse responses (when the variables are in changes?). I tried using the accumulate instruction inside the loop but didn't succeed in getting the code to run so I'm sure I used it the wrong way and in the wrong place within the loop. Any help would be much appreciated.
Code: Select all
*
* Monte Carlo integration with shock to "exogenous" variable
*
compute lags=4 ;*Number of lags
compute nstep=16 ;*Number of response steps
compute ndraws=10000 ;*Number of keeper draws
*
open data haversample.rat
cal(q) 1959
data(format=rats) 1959:1 2006:4 ftb3 gdph ih cbhm
*
set loggdp = log(gdph)
set loginv = log(ih)
set logc = log(cbhm)
*
* T-Bill rate is treated as exogenous
*
system(model=varmodel)
variables loggdp loginv logc
lags 1 to lags
det constant ftb3{1 to 4}
end(system)
*
* Define placeholder equation to allow shock to T-bills.
*
equation(empty) rateeq ftb3
*
******************************************************************
estimate
compute nshocks=1
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
*
* On the odd values for <<draw>>, a draw is made from the inverse Wishart
* distribution for the covariance matrix. This assumes use of the
* Jeffrey's prior |S|^-(n+1)/2 where n is the number of equations in
* the VAR. The posterior for S with that prior is inverse Wishart with
* T-p d.f. (p = number of explanatory variables per equation) and
* covariance matrix inv(T(S-hat)).
*
* Given the draw for S, a draw is made for the coefficients by adding
* the mean from the least squares estimate to a draw from a
* multivariate Normal with (factor of) covariance matrix as the
* Kroneker product of the factor of the draw for S and a factor of
* the X'X^-1 from OLS.
*
* On even draws, the S is kept at the previous value, and the
* coefficient draw is reflected through the mean.
*
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)
*
* Shock the combination of the VAR + the placeholder equation with a
* unit shock to the placeholder.
*
impulse(noprint,model=varmodel+rateeq,shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
*
* Save the impulse responses
*
dim %%responses(draw)(nvar*nshocks,nstep)
ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
infobox(current=draw)
end do draw
infobox(action=remove)
*
@mcgraphirf(model=varmodel,shocklabels=||"To Interest Rate"||)
Re: Shock in exogenous variables in a SVAR
Why don't you post what you did that didn't work? It would make more sense to try to fix that than for me to add it to an inappropriate model.
Re: Shock in exogenous variables in a SVAR
This is the code that I'm trying to run:
I am not sure that I am doing the accumulation of the responses in the right way. in fact, I only need to accumulate the response to the first (differenced) variable in the VAR model (the variable dgcf1l). The responses to the other variables don't really need to be accumulated. When I run the above code I get the error message "## SR6. Missing a Necessary Parameter. Check Instruction Syntax The Error Occurred At Location 358, Line 41 of loop/block" and the error occurs in the loop that saves the responses (last loop in the program). I also want to make sure that I am plotting the accumulated response to the first variable and not the first differenced response. Your help with this would be greatly appreciated.
Code: Select all
*
* Monte Carlo integration with shock to "exogenous" variable
*
compute lags=2 ;*Number of lags
compute nstep=12 ;*Number of response steps
compute ndraws=5000 ;*Number of keeper draws
*
calendar(m) 1990:01
allocate 2010:01
open data "C:\Documents and Settings\ij08\My Documents\WinRats 7.3\M.XLS"
data(format=xls,org=columns) /
**define variables
set fff1rate = 100-ffff1
set mpshock = fftr-fff1rate{1}
diff gcf1l / dgcf1l
*
* The shock is traded as exogenous
*
system(model=varmodel)
variables dgcf1l gccyl gcsp gchp
lags 1 to lags
det constant mpshock{1}
end(system)
*
* Define placeholder equation to allow exogenous
*
equation(empty) mpshockeq mpshock
*
******************************************************************
estimate
compute nshocks=1
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
*
* On the odd values for <<draw>>, a draw is made from the inverse Wishart
* distribution for the covariance matrix. This assumes use of the
* Jeffrey's prior |S|^-(n+1)/2 where n is the number of equations in
* the VAR. The posterior for S with that prior is inverse Wishart with
* T-p d.f. (p = number of explanatory variables per equation) and
* covariance matrix inv(T(S-hat)).
*
* Given the draw for S, a draw is made for the coefficients by adding
* the mean from the least squares estimate to a draw from a
* multivariate Normal with (factor of) covariance matrix as the
* Kroneker product of the factor of the draw for S and a factor of
* the X'X^-1 from OLS.
*
* On even draws, the S is kept at the previous value, and the
* coefficient draw is reflected through the mean.
*
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)
*
* Shock the combination of the VAR + the placeholder equation with a
* unit shock to the placeholder.
*
impulse(noprint,model=varmodel+mpshockeq,shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
*Accumulate the responses
declare vect[int] accum
do i=1,3
acc impulses(accum(i),1) 1 nstep
acc impulses(accum(i),2) 1 nstep
acc impulses(accum(i),3) 1 nstep
end do i
*
* Save the impulse responses
*
dim %%responses(draw)(nvar*nshocks,nstep)
ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
infobox(current=draw)
end do draw
infobox(action=remove)
*
@mcgraphirf(model=varmodel,shocklabels=||"To MP shock"||)
Re: Shock in exogenous variables in a SVAR
This is what isn't correct:
declare vect[int] accum
do i=1,3
acc impulses(accum(i),1) 1 nstep
acc impulses(accum(i),2) 1 nstep
acc impulses(accum(i),3) 1 nstep
end do i
The <<accum>> is for listing the set of variables that need to be accumulated, and that would need to be created and filled outside the loop. You don't need it here since you have just the one. Also, the "3" in the do loop control is for the number of elements in <<accum>>, which is again, just 1 here. The 1,2 and 3 lines would be for a model with three shocks; you have five. So you want either:
acc impulses(1,1) 1 nstep
acc impulses(1,2) 1 nstep
acc impulses(1,3) 1 nstep
acc impulses(1,4) 1 nstep
acc impulses(1,5) 1 nstep
or
do j=1,5
acc impulses(1,j) 1 nstep
end do j
declare vect[int] accum
do i=1,3
acc impulses(accum(i),1) 1 nstep
acc impulses(accum(i),2) 1 nstep
acc impulses(accum(i),3) 1 nstep
end do i
The <<accum>> is for listing the set of variables that need to be accumulated, and that would need to be created and filled outside the loop. You don't need it here since you have just the one. Also, the "3" in the do loop control is for the number of elements in <<accum>>, which is again, just 1 here. The 1,2 and 3 lines would be for a model with three shocks; you have five. So you want either:
acc impulses(1,1) 1 nstep
acc impulses(1,2) 1 nstep
acc impulses(1,3) 1 nstep
acc impulses(1,4) 1 nstep
acc impulses(1,5) 1 nstep
or
do j=1,5
acc impulses(1,j) 1 nstep
end do j
Re: Shock in exogenous variables in a SVAR
Thanks Tom. When I do the following:
things work fine. However, if I do:
I get the error message "## SR6. Missing a Necessary Parameter. Check Instruction Syntax The Error Occurred At Location 0363 of loop/block Line 40 of loop/block". In any case, I just need to accumulate the first response, so the first snippet of code that works is enough. Three final questions: are the responses to postive or negative shocks to the exogenous variable? What is the magnitude of the shock to the exogenous variable? Can I also plot the exogenous variable's response to itself?
Code: Select all
* Shock the combination of the VAR + the placeholder equation with a
* unit shock to the placeholder.
*
impulse(noprint,model=varmodel+mpshockeq,shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
*Accumulate the responses
acc impulses(1,1) 1 nstep
* Save the impulse responses
*
dim %%responses(draw)(nvar*nshocks,nstep)
ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
infobox(current=draw)
end do draw
infobox(action=remove)
*
@mcgraphirf(model=varmodel,shocklabels=||"To MP shock"||)
Code: Select all
* Shock the combination of the VAR + the placeholder equation with a
* unit shock to the placeholder.
*
impulse(noprint,model=varmodel+mpshockeq,shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
*Accumulate the responses
acc impulses(1,1) 1 nstep
acc impulses(1,2) 1 nstep
acc impulses(1,3) 1 nstep
acc impulses(1,4) 1 nstep
acc impulses(1,5) 1 nstep
* Save the impulse responses
*
dim %%responses(draw)(nvar*nshocks,nstep)
ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
infobox(current=draw)
end do draw
infobox(action=remove)
*
@mcgraphirf(model=varmodel,shocklabels=||"To MP shock"||)
Re: Shock in exogenous variables in a SVAR
Sorry. You're right. The first is correct since it is only generating responses to one shock, not the whole set.
It's a unit shock. It sounds like what you want is very different from the original question. You need to create an equation for T-Bills (probably a univariate autoregression) and create a model combining the VAR with t-bill lags and the separate equation for the t-bills. You can't, however, do any simple Monte Carlo integration on that since it doesn't have a simple form.
It's a unit shock. It sounds like what you want is very different from the original question. You need to create an equation for T-Bills (probably a univariate autoregression) and create a model combining the VAR with t-bill lags and the separate equation for the t-bills. You can't, however, do any simple Monte Carlo integration on that since it doesn't have a simple form.
Re: Shock in exogenous variables in a SVAR
Thanks for the reply Tom. Given that my exogenous variable is measured in percent, a unit shock is then a +1% shock to the exogenous variable, right? How can I change the magnitude and sign of the shock to the exogenous variable to -1% or -0.25%,for example?
Re: Shock in exogenous variables in a SVAR
I think I figured this out. I can use the shocks option on the impulse command:
to shock only the exegenous variable by -0.25. Am I doing this the right way? The original code that Tom wrote shocks all the variables by one unit (and not only the exogenous variable):
and my responses when I alter the code seem to have the unexpected signs.
Code: Select all
impulse(noprint,model=varmodel+mpshockeq,shocks=||0,0,0,0,-0.25||,$
result=impulses,steps=nstep)
Code: Select all
impulse(noprint,model=varmodel+mpshockeq,shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
Re: Shock in exogenous variables in a SVAR
shocks=%unitv(%nvar+1,%nvar+1) does a unit shock to the final equation, which is the place holder for the exogenous variable. With five variables, it's equivalent to shocks=||0,0,0,0,1.0||. What you are doing would give a -.25 shock. Given the linearity of the model, the responses should be -.25 times the unit shocks.
Re: Shock in exogenous variables in a SVAR
Dear Tom, sorry for your taking your time again.Ozmando wrote:Hi Everyone. I need more help with this code please. Is there a way to modify the code so that the impulse response functions graph only the response to the exogenous shocks? Thanks. Oz
Is there a way to modify this code such that it captures the exogenous shock as well as one of the endogenous shock.
Thanks,
oz
Re: Shock in exogenous variables in a SVAR
Sure. The way of handling the exogenous shock was to "endogenize" it into the model. So you could just do any set of shocks you want to the combined model.
Re: Shock in exogenous variables in a SVAR
I am trying to run this code below but it seems to crash with the following error: "## MAT5. Needed Matrix with Dimensions 5 x 1, Got 2 x 1 Instead".
Any help please?
oz
Any help please?
oz
Code: Select all
*
*
* Monte Carlo integration with shock to "exogenous" variable
*
compute lags=4 ;*Number of lags
compute nstep=16 ;*Number of response steps
compute ndraws=10000 ;*Number of keeper draws
*
open data "C:\Program Files (x86)\Estima\WinRATS 7\haversample.rat"
cal(q) 1959
data(format=rats) 1959:1 2006:4 ftb3 gdph ih cbhm
*
set loggdp = log(gdph)
set loginv = log(ih)
set logc = log(cbhm)
*
* T-Bill rate is treated as exogenous
*
setset dftb3 = ftb3 - ftb3{1}
equation(coeffs=||1.0,-1.0||,identity) dratedef dftb3
# loggdp loginv logc ftb3{0 1}
system(model=vecmmodel)
variables loggdp loginv logc
lags 1 to lags
ect ect1
det constant dftb3{0 to 3}
end(system)
*
* Define placeholder equation to allow shock to T-bills.
*
equation(empty) rateeq ftb3
*
******************************************************************
estimate
dec rect lr(3,3) sr(3,3)
input lr
. . .
. . .
. . .
input sr
. . 0
. . 0
. 0 .
dec rect rh(1,4) rv(3,1)
input rv
0 0 0
input rh
0 0 0 1
dis rv rh
impulse(model=%modelsubstect(vecmmodel),factor=%identity(3),results=baseimp,noprint,steps=500)
compute lrsum=%xt(baseimp,500)
@ShortAndLong(lr=lr,sr=sr,masum=lrsum) %sigma f
compute f=f~rv~~rh
impulse(noprint,model=%modelsubstect(vecmmodel)+rateeq+dratedef, factor=%identity(4), shocks=%unitv(%nvar+1,%nvar+1),$
result=impulses,steps=nstep)
Re: Shock in exogenous variables in a SVAR
First of all, "Edit-Show Last Error" will point you to the instruction which caused the error which is:
equation(coeffs=||1.0,-1.0||,identity) dratedef dftb3
# loggdp loginv logc ftb3{0 1}
You're giving two coefficients for an equation with five explanatory variables.
equation(coeffs=||1.0,-1.0||,identity) dratedef dftb3
# loggdp loginv logc ftb3{0 1}
You're giving two coefficients for an equation with five explanatory variables.