Shock in exogenous variables in a SVAR

Questions and discussions on Vector Autoregressions
Ozmando
Posts: 52
Joined: Sun Jul 15, 2012 4:04 pm

Re: Shock in exogenous variables in a SVAR

Unread post by Ozmando »

Thanks Tom for the tip and also for pointing to the error.
I managed to fix it now. Posting the code below in case someone else want to use it.
Thanks,
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 exogenoussetset dftb3  = ftb3 - ftb3{1}
equation(coeffs=||1.0,-1.0||,identity) dratedef dftb3
# 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)
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Shock in exogenous variables in a SVAR

Unread post by pfb382 »

In terms of impulse response function of completely exogenous variables in a VECM-X model, does it matter which identification procedure I chose for the endogenous variables or is that unrelated?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Shock in exogenous variables in a SVAR

Unread post by TomDoan »

No. The identification of the shocks on the endogenous variables has no effect on how shocks to exogenous variables behave.
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Shock in exogenous variables in a SVAR

Unread post by pfb382 »

Great, Tom. Thanks so much. So I have an VECM with 2 cointegration relationships (stationary inflation) and 3 strongly exogenous variables that should enter contemporaneously as well as the first lag. I want to see the impulse responses of my 3 exogenous variables on my endogenous (with condi. I have tried to merge the codes in this thread, but i don't know:

... 1. where my mistake is that I get the error: "## SC1. Expected Supplementary Card (# ....) Here >>>>e<<<<"
2. how to correctly model it for 3 exogenous variables simultaneously... or shall I do them in turns?
3. Where can I set the width of the confidence bands?
4. Can I see the parameter estimates anywhere so I can compare if the IRFs are indeed based on the coefficients I estimated in CATS.

THANKS!

I post my code here:

Code: Select all

*
    *
    * Monte Carlo integration with shock to "exogenous" variable
    *
    compute lags=2            ;*Number of lags
    compute nstep=20         ;*Number of response steps
    compute ndraws=10000      ;*Number of keeper draws
    *
    open data "C:\..\Newfolder\FINAL1"
   calendar 1970 1 1
   all 2015:1
    data(format=xls,org=col) 1970:1 2015:1 lwEAC_B	lBuGDP	wEACI_B	BuIn	W	TOTC	OP	trend	DUM94	DUM9397	DUM15

    *
equation(coeffs=||0,0,1,0||) ect1
equation(coeffs=||0,0,0,1||) ect2
# lwEAC_B lBuGDP wEACI_B BuIn

    system(model=vecmodel)
    variables lwEAC_B lBuGDP wEACI_B BuIn
    lags 1 to lags
    ect ect1 ect2
    det constant trend DUM94 DUM15 DUM9397 TOTC{0 to 1} OP{0 to 1} W{0 to 1}
    end(system)
    *
    * Define placeholder equation to allow shock to TOTC OP and W.
    *
    equation(empty) toteq TOTC
equation(empty) oileq OP
equation(empty) worldeq W
    *
    ******************************************************************
    estimate
compute nshocks=1
compute nvar   =%nvar
compute fxx    =%decomp(%xx)
compute fwish  =%decomp(inv(%nobs*%sigma))
compute wishdof=%nobs-%nreg
compute betaols=%modelgetcoeffs(vecmodel)
*
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(vecmodel,betadraw)
   *
   * Shock the combination of the VAR + the placeholder equation with a
   * unit shock to the placeholder.
   *
   impulse(noprint,model=vecmodel+toteq+oileq+worldeq,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=vecmodel,shocklabels=||"To TOT"||,||"To Oilp"||,||"To World GDP"||)

Attachments
FINAL1.xls
(38.5 KiB) Downloaded 648 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Shock in exogenous variables in a SVAR

Unread post by TomDoan »

The first of these two is missing the supplementary card:

equation(coeffs=||0,0,1,0||) ect1
equation(coeffs=||0,0,0,1||) ect2
# lwEAC_B lBuGDP wEACI_B BuIn

Note that as written (correctly), these are saying that WEACI_B and BUIN are stationary. Is that what you intend?
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Shock in exogenous variables in a SVAR

Unread post by pfb382 »

Ah ok. thanks.

So i added # lwEAC_B lBuGDP wEACI_B BuIn underneath the first equation as well. And yes, those two variables are stationary.
It seems to work now. But for some reason my RATS always completely crashes and shut down as soon as the MC simulation starts (the estimation though seems to work). Do you know why this might be the case? .. I have tried it only with one exogenous at a time, but that didnt help either.
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Shock in exogenous variables in a SVAR

Unread post by pfb382 »

Hi Tom,

I have tried it on different PCs, reinstalled RATS, shortened the equation, ... but RATS keeps crashing when the the Progress Box of the MC integration appears. Why is that? Thanks!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Shock in exogenous variables in a SVAR

Unread post by TomDoan »

You need version 9.2 to do the draws from a VECM using simple methods.
Post Reply