38 posts
• Page **1** of **3** • **1**, 2, 3

Hello. I could help. How I can generate shocks of 1% in the exogenous variables in a SVAR program?

Thanks for any help! (e-mail address: torresgc@bccr.fi.cr)

Thanks for any help! (e-mail address: torresgc@bccr.fi.cr)

- torresgc
**Posts:**1**Joined:**Mon Aug 08, 2011 5:38 pm

torresgc wrote:Hello. I could help. How I can generate shocks of 1% in the exogenous variables in a SVAR program?

Thanks for any help! (e-mail address: torresgc@bccr.fi.cr)

This may be a bit more than you need (it does MC integration for the response), but it shows the general idea. You create a placeholder equation which has the exogenous variable as its dependent variable, and shock that using the SHOCKS option on IMPULSE. To get 1%, you would use the option

shocks=.01*%unitv(%nvar+1,%nvar+1)

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

- TomDoan
**Posts:**5852**Joined:**Wed Nov 01, 2006 5:36 pm

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

- Ozmando
**Posts:**15**Joined:**Sun Jul 15, 2012 4:04 pm

That's what this does. The only shock analyzed is to the variable treated as exogenous.

- TomDoan
**Posts:**5852**Joined:**Wed Nov 01, 2006 5:36 pm

TomDoan wrote:That's what this does. The only shock analyzed is to the variable treated as exogenous.

TomDan thanks. However, I notice that the IFR of LOGC do not correspond to the estimates of the coefficients of FTB(?) They appear to be fine for other variables.

- Ozmando
**Posts:**15**Joined:**Sun Jul 15, 2012 4:04 pm

Look fine to me. LOGC is the only equation that has a negative coefficient on lag one of FTB3. Beyond lag one, it's very hard to tell what will happen just by eyeballing the coefficients.

- TomDoan
**Posts:**5852**Joined:**Wed Nov 01, 2006 5:36 pm

More query please: if I read the data into rats into a panel format and I introduce country dummies as exogenous variables. Can that be treated as a panel SVAR? If not is there a way to estimate panel SVAR in the context of exogenous shocks?

Thanks

oz

Thanks

oz

- Ozmando
**Posts:**15**Joined:**Sun Jul 15, 2012 4:04 pm

In your panel SVAR, what's heterogeneous and what's homogeneous? What you're describing would seem to have only the intercepts being heterogeneous, which is a rather strong assumption, generally only appropriate if you have a limited amount of data per country. And if you have that, then the small-sample bias in the fixed effects estimator could be quite severe.

- TomDoan
**Posts:**5852**Joined:**Wed Nov 01, 2006 5:36 pm

TomDoan wrote:That's what this does. The only shock analyzed is to the variable treated as exogenous.

Hi Tom,

Sorry to bother again: If I am right the coefficients obtained are the mean response? is there away to also obtain the cumulative response (let's say after 3 period) and their confidence band?

Thanks

Oz

- Ozmando
**Posts:**15**Joined:**Sun Jul 15, 2012 4:04 pm

Use the ACCUMULATE instruction. See, for instance, what the BQDODRAWS procedure does.

- TomDoan
**Posts:**5852**Joined:**Wed Nov 01, 2006 5:36 pm

I am estimating a vector error correction model (vecm) and a shock to the exogenous variable as described above does not work. Any suggestion?

Best,

Best,

- wfirew
**Posts:**5**Joined:**Thu Jun 21, 2012 8:16 am

wfirew wrote:I am estimating a vector error correction model (vecm) and a shock to the exogenous variable as described above does not work. Any suggestion?

Best,

Why not?

- TomDoan
**Posts:**5852**Joined:**Wed Nov 01, 2006 5:36 pm

It works fine for VAR. Then, I have modified the code as follow for vecm (leaving the MC part). When I run it, the programs freezes prompting me to close the program.

I have one more concern that is dftb3 is just another exogenous variable instead of the difference of ftb3. But I want the difference of ftb3 outside the co-integrating vector as an exogenous while ftb3 is in the cointegrating vector.

- Code: Select all
`*`

* Monte Carlo integration with shock to "exogenous" variable

*

compute lags=4 ;*Number of lags

compute nstep=16 ;*Number of response steps

*

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

*

setset dftb3 = ftb3 - ftb3{1}

equation(coeffs=||1.0,0.3,0.3,0.3||) ect1

# loggdp loginv logc ftb3

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

impulse(noprint,model=vecmmodel+rateeq,shocks=%unitv(%nvar+1,%nvar+1),$

result=impulses,steps=nstep)

I have one more concern that is dftb3 is just another exogenous variable instead of the difference of ftb3. But I want the difference of ftb3 outside the co-integrating vector as an exogenous while ftb3 is in the cointegrating vector.

- wfirew
**Posts:**5**Joined:**Thu Jun 21, 2012 8:16 am

You need the %MODELSUBSTECT function as shown in this:

impulse(noprint,model=%modelsubstect(vecmmodel)+rateeq,shocks=%unitv(%nvar+1,%nvar+1),$

result=impulses,steps=nstep)

impulse(noprint,model=%modelsubstect(vecmmodel)+rateeq,shocks=%unitv(%nvar+1,%nvar+1),$

result=impulses,steps=nstep)

- TomDoan
**Posts:**5852**Joined:**Wed Nov 01, 2006 5:36 pm

Thanks for the quick response Tom,

It is working now. I have one question tough. I wanted to use short and long to identify other shocks. Therefore, I coded (using just sr restriction as an example) as attached below. Is this a correct way?

I know that it does not matter for the particular shock to the exogenous variable.

One last question which was not clearly put on the last post was about including the difference of ftb3 (the exogenous variable) in the VECM. Assuming ftb3 is I(1), I have to difference it before including it in the VECM where everything is I(0). But, the way I did it a shock to ftb3 does not affect dftb3 (=ftb3 - ftb3 {1})

I want a shock to ftb3 to also affect dftb3. How do I do that?

It is working now. I have one question tough. I wanted to use short and long to identify other shocks. Therefore, I coded (using just sr restriction as an example) as attached below. Is this a correct way?

I know that it does not matter for the particular shock to the exogenous variable.

One last question which was not clearly put on the last post was about including the difference of ftb3 (the exogenous variable) in the VECM. Assuming ftb3 is I(1), I have to difference it before including it in the VECM where everything is I(0). But, the way I did it a shock to ftb3 does not affect dftb3 (=ftb3 - ftb3 {1})

I want a shock to ftb3 to also affect dftb3. How do I do that?

- 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,0.3,0.3,0.3||) ect1

# loggdp loginv logc ftb3

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, factor=f, $

result=impulses,steps=nstep)

- wfirew
**Posts:**5**Joined:**Thu Jun 21, 2012 8:16 am

38 posts
• Page **1** of **3** • **1**, 2, 3

Return to VARs (Vector Autoregression Models)

Users browsing this forum: No registered users and 1 guest