Identification by Sign-Restrictions PLUS Zero-Restrictions

Questions and discussions on Vector Autoregressions

Identification by Sign-Restrictions PLUS Zero-Restrictions

Unread postby jonasdovern » Fri Mar 06, 2015 8:18 am

I am trying to implement code for an SVAR with identification of multiple shocks by a combination of sign-restrictions and zero-restrictions.

I am trying to modify the code from the replication files for Mountford and Uhlig (2009). I am struggling with doing this for nshocks>1.

I modified the code for identification of the first part by restricting the rotation vector as follows:
Code: Select all
      ************************************************
      * First in Order - Supply Shock
      ************************************************
      compute [vector] v1=%zeros(1,1)~~%ransphere(nvar-1)
      if UhligAccept(v1,KMIN,KMAX,||+2,-3||)==0
         goto reject
      compute i1=p*v1

By this I can make sure that the first variable does not respond on impact to the first structural shock.

The code goes on with forcing i1 as one column in the factorization ...
Code: Select all
      @forcedfactor(force=column) sigmad i1 f
      compute r2=inv(p)*%xsubmat(f,1,nvar,2,nvar)

... and identifying the next shock:
Code: Select all
      *****************************************************
      *  Second in Order - Demand Shock
      *****************************************************
      compute [vector] v2=r2*%ransphere(nvar-1)
      if UhligAccept(v2,KMIN,KMAX,||+1,+2,+3||)==0
         goto reject
      compute i2=p*v2

The point at which I am struggling is how to impose the same zero-restriction also for this second shock (variable 1 should not respond also to the second shock on impact). How can I find the second rotation vector such that its first element is 0 and that it "fits" to the first one in terms of the orthogonality condition? I couldn't find any example in the replication section that uses a similar identification scheme.
jonasdovern
 
Posts: 97
Joined: Sat Apr 11, 2009 10:30 am

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby TomDoan » Fri Mar 06, 2015 10:25 am

Isn't the mu2009b2.rpf example largely on point? It has zero restrictions on the fiscal policy shocks. You just have to do the restrictions based upon the impulse responses even if they're just impact restrictions.
TomDoan
 
Posts: 7147
Joined: Wed Nov 01, 2006 5:36 pm

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby jonasdovern » Mon Mar 09, 2015 1:32 pm

Thanks, Tom, for pointing me to the panelty-function example with delayed shocks. I hadn't browsed these as I want to use the "pure sign-restriction approach" and did not find them via a text search.

Translating this code worked out well. I am posting my code below as an example for other RATS users that want to estimate similar models. (This is based on a four-variable VAR and the initial response of the first variable to the first and the second shock is restricted to be equal to zero.)
Code: Select all
*** Setup for Structural Estimation
dec vect[strings] vl(10)
compute vl=||"Infl. Exp.","GDP","CPI","Policy Rate"||
compute nvar  =4
compute nstep =40
compute nkeep=1000
compute n1   =500
compute n2   =1000
compute KMIN  =1
compute KMAX  =2
*
* Compute scale factors for impulse responses
*
compute [vector] scales=%sqrt(%xdiag(%sigma))
*
* This is the standard setup for MC integration of an OLS VAR
*
compute sigmad =%sigma
compute sxx    =%decomp(%xx)
compute svt    =%decomp(inv(%nobs*%sigma))
compute betaols=%modelgetcoeffs(mu_model_1)
compute ncoef  =%rows(sxx)
compute wishdof=%nobs-ncoef
*
dec vect[rect] %%responses
dim %%responses(nkeep)
*
dec rect[series] impulses
declare series[rect] irfsquared
*
source uhligfuncs.src
*
* Parameter vectors for the nested optimization problems. They should
* have a size equal to nvar less 1 + the number of constraints imposed
* prior to their estimation. Those prior constraints can be
* orthogonality to previous shocks, or can be zero restrictions.
*
compute nshocks=3
dec vect[strings] sl(nshocks)
compute sl=||"Supply","Demand","Monetary Policy"||
*
*******************************************************************************
declare vector ik a(nvar) ones(nvar)
compute ones=%const(1.0)
source forcedfactor.src
*
infobox(action=define,progress,lower=1,upper=n1) "Monte Carlo Integration"
compute accept=0
do draw=1,n1
   *
   * Make a draw from the posterior for the VAR and compute its impulse
   * responses.
   *
   compute sigmad  =%ranwisharti(svt,wishdof)
   compute p       =%decomp(sigmad)
   compute betadraw=betaols+%ranmvkron(p,sxx)
   compute %modelsetcoeffs(mu_model_1,betadraw)
   *
   impulse(noprint,model=mu_model_1,factor=p,results=impulses,steps=nstep)
   *
   do subdraw=1,n2
      ************************************************
      * First in Order - Supply Shock
      ************************************************
      compute [vector] v1=%zeros(1,1)~~%ransphere(nvar-1)
      if UhligAccept(v1,KMIN,KMAX,||+2,-3||)==0
         goto reject
      compute i1=p*v1
      *
      *****************************************************
      *  Second in Order - Demand Shock
      *****************************************************
      dec rect r(1,nvar)
      ewise r(i,j)=ix=%xt(impulses,i),ix(1,j)
      @forcedfactor(force=column) sigmad i1~p*tr(r) f
      compute r2=inv(p)*%xsubmat(f,1,nvar,2,nvar)
      compute [vector] v2=r2*(%zeros(1,1)~~%ransphere(nvar-2))
      if UhligAccept(v2,KMIN,KMAX,||+1,+2,+3||)==0
         goto reject
      compute i2=p*v2
      *
      *****************************************************
      *  Third in Order - Monetary Policy Shock
      *****************************************************
      @forcedfactor(force=column) sigmad i1~i2 f
      compute r3=inv(p)*%xsubmat(f,1,nvar,3,nvar)
      compute [vector] v3=r3*(%ransphere(nvar-2))
      if UhligAccept(v3,KMIN,KMAX,||+2,+3,-4||)==0
         goto reject
      compute i3=p*v3
      *
      * Meets all restrictions
      *
      compute accept=accept+1
      dim %%responses(accept)(nshocks*nvar,nstep)
      *
      * Save the desired sets of linear combinations of the Choleski
      * responses
      *
      compute vweights=v1~v2~v3
      ewise %%responses(accept)(i,j)=(ik=%vec(%xt(impulses,j)*vweights)),ik(i)
      if accept>=nkeep
         break
   :reject
   end do subdraw
   if accept>=nkeep
      break
   infobox(current=draw)
   :newdraw
end do draw
infobox(action=remove)
disp "Acceptances" accept "on" draw "main draws"

jonasdovern
 
Posts: 97
Joined: Sat Apr 11, 2009 10:30 am

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby economarvell » Thu Aug 10, 2017 11:13 am

Dear jonasdovern,

Thank you very much for sharing this!
My question might be trivial: how do you restrict the initial response to a shock of the first and second variable to zero?
Since I am new to RATS, I do not see immediately in your code what imposed the zero restriction...

Thank you in advance!
economarvell
 
Posts: 4
Joined: Thu Aug 10, 2017 10:18 am

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby TomDoan » Thu Aug 10, 2017 3:36 pm

In the above, this is the processing for the second shock. This has to be orthogonal to the first shock, and also the design is to have it have a zero impact on the variable 1:

dec rect r(1,nvar)
ewise r(i,j)=ix=%xt(impulses,i),ix(1,j)
@forcedfactor(force=column) sigmad i1~p*tr(r) f
compute r2=inv(p)*%xsubmat(f,1,nvar,2,nvar)
compute [vector] v2=r2*(%zeros(1,1)~~%ransphere(nvar-2))

A somewhat cleaner way to write the last three lines is

compute forcedcols=i1~p*tr(r)
@forcedfactor(force=column) sigmad forcedcols f
compute r2=inv(p)*%xsubmat(f,1,nvar,%cols(forcedcols)+1,nvar)
compute v2=r2*%ransphere(%cols(r2))

If you look at the current versions of the Mountford-Uhlig examples, you'll see them written that way and you should probably work off those rather than this.

The R is what codes up the zero impact restriction(s). In this case, there's just one. If you want to change this to force zero impacts on 1 and 2, you would need

dec rect r(2,nvar)
ewise r(i,j)=ix=%xt(impulses,1),ix(i,j)

The "i" in the above example was taken from an example that did multiple steps on a single variable---now it does multiple variables at a single step (%xt(impulses,1) is the N x N matrix of impacts with shocks in the columns and variables in the rows).
TomDoan
 
Posts: 7147
Joined: Wed Nov 01, 2006 5:36 pm

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby economarvell » Fri Aug 11, 2017 5:23 am

Dear Tom,

Thank you very much for your helpful answer.
I tried implementing the code for only one shock but got an "## SX11. Identifier I1 is Not Recognizable." error which I could not work around...
My idea is to identify only one shock and restrict the signs on impact of the first, second and sixth variable to zero while implementing sign restrictions for the remaining ones. Would you kindly have any advice on doing so with your code above?

Kind regards and many thanks!
economarvell
 
Posts: 4
Joined: Thu Aug 10, 2017 10:18 am

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby TomDoan » Fri Aug 11, 2017 9:26 am

i1 doesn't exist when you're picking the first shock. You have no sign restrictions on the first shock? Three zero restrictions isn't going to be much of a restriction (for instance, it doesn't fix the sign of any response, and will give roughly equal +/- signs on all the other impacts).
TomDoan
 
Posts: 7147
Joined: Wed Nov 01, 2006 5:36 pm

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby economarvell » Fri Aug 11, 2017 9:56 am

I do have three sign restrictions and three zero restrictions on the first and only identified shock. There is only one unrestricted variable.
Shouldn't this work?
economarvell
 
Posts: 4
Joined: Thu Aug 10, 2017 10:18 am

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby TomDoan » Fri Aug 11, 2017 1:11 pm

If you work off the newer versions of the Mountford-Uhlig programs, your first shock would be done with something like (this is for the rejection method):

compute step0=%xt(impulses,1)
compute rirf=%xrow(step0,1)~~%xrow(step0,2)~~%xrow(step0,6)
compute forcedcols=sigmap*tr(rirf)
@forcedfactor(force=column) sigmad forcedcols ffactor
compute r1=inv(sigmap)*%xsubmat(ffactor,1,nvar,%cols(forcedcols)+1,nvar)
compute [vector] v1=r1*%ransphere(%cols(r1))
if UhligAccept(v1,KMIN,KMAX,||your sign restrictions||)==0
goto reject
compute i1=sigmap*v1
TomDoan
 
Posts: 7147
Joined: Wed Nov 01, 2006 5:36 pm

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby economarvell » Sat Aug 19, 2017 2:36 pm

Dear Tom,

is it possible to retrieve the parameters of the underlying reduced form VAR?
Moreover, when changing variables in the model, I get the following error message

"## MAT1. Matrix %%RESPONSES(2) Has Not Been Dimensioned
The Error Occurred At Location 776, Line 43 of loop/block"

where the number after RESPONSES differs from iteration to iteration. Would you know what the matter is?
economarvell
 
Posts: 4
Joined: Thu Aug 10, 2017 10:18 am

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby TomDoan » Sun Aug 20, 2017 9:57 pm

economarvell wrote:Dear Tom,

is it possible to retrieve the parameters of the underlying reduced form VAR?


I'm not sure what you mean. Sign restrictions very specifically don't have a model.

economarvell wrote:Moreover, when changing variables in the model, I get the following error message

"## MAT1. Matrix %%RESPONSES(2) Has Not Been Dimensioned
The Error Occurred At Location 776, Line 43 of loop/block"

where the number after RESPONSES differs from iteration to iteration. Would you know what the matter is?


Sounds like you never set NSHOCKS which is the number of shocks you're saving

dim %%responses(accept)(nshocks*nvar,nstep)
TomDoan
 
Posts: 7147
Joined: Wed Nov 01, 2006 5:36 pm

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby KOBE24 » Tue Feb 12, 2019 7:27 pm

Dear Tom,

I am struggling in understanding whether the IRFs of my VAR are satisfying my desired mix of zero and sign restrictions. As a matter of fact, I feel I am doing something wrong in imposing the zeros (i.e. building the matrices), but I hope to clarify in a second.

I basically have a 5 variables VAR model (oil price, policy rate, term spread, consumer prices and real GDP in that order just to have a candidate Cholesky as a starting point with some convenient choices for imposing zeros). I rely on codes based on Mountford -Uhlig (2009) and your suggestions (as I understood them).
1. The first thing I want to do is to impose that an aggregate supply shock has a zero impact on oil price (in order to disentangle "real" supply from oil supply disturbances)
2. the second one is to identify a spread compression shock (Baumeister & Benati, IJCB 2013), and to do so I put a zero on the policy rate.
3. finally, when looking at oil supply shocks, I also want to impose that they do not move the term spread on impact (zerio restriction).

Below is my code. Could you please tell me whether it is correct, based also on the graph that I am attaching? In particular, I do not get whether by using the constraints I posted below I should also see restricted to zero, for example, oil price in the unconventional monetary shock. In this case, I could have "well behaved" IRFs just by chance.

Thanks in advance for your time and help, I am really struggling on a deadline because of this.

Code: Select all
   do subdraw=1,n2

******* =========================================================== *******
******* First in Order - Domestic supply shock (one zero on oil price)               *******
******* =========================================================== *******

      compute [vector] v1=%zeros(1,1)~~%ransphere(4)
      if UhligAccept(v1,KMIN,KMAX,||+2,+4,-5||)==0
         goto reject
      compute i1=p*v1

******* =========================================================== *******
******* Second in Order - Unconventional MP shock(one zero on rate)              *******
******* =========================================================== *******
      dec rect r(1,nvar)
      ewise r(i,j)=ix=%xt(impulses,i),ix(2,j)
      @forcedfactor(force=column) sigmad i1~p*tr(r) f
      compute r2=inv(p)*%xsubmat(f,1,nvar,2,nvar)
      compute [vector] v2=r2*(%zeros(1,1)~~%ransphere(nvar-2))
      if UhligAccept(v2,KMIN,KMAX,||-3,+4,+5||)==0
        goto reject
      compute i2=p*v2
   
******* =========================================================== *******
******* Third in Order - Oil Supply Shock (one zero on tspread)                        *******
******* =========================================================== *******
      dec rect r(1,nvar)
      ewise r(i,j)=ix=%xt(impulses,i),ix(3,j)
      @forcedfactor(force=column) sigmad i1~i2~p*tr(r) f
      compute r3=inv(p)*%xsubmat(f,1,nvar,3,nvar)
      compute  [vector] v3 = r3*(%zeros(1,1)~~%ransphere(nvar-3))
      if UhligAccept(v3,KMIN,KMAX,||+1,+4,-5||)==0
        goto reject
      compute i3=p*v3
      *dis v3

Attachments
IRFS_for_TomDoan.pdf
(168.16 KiB) Downloaded 492 times
KOBE24
 
Posts: 51
Joined: Tue Jul 21, 2009 9:10 am

Re: Identification by Sign-Restrictions PLUS Zero-Restrictio

Unread postby sak777 » Fri Sep 10, 2021 9:21 am

Hi Tom,

I am trying to estimate a 5 variable VAR using sign and zero restrictions. I am following Mountford and Uhlig (2009) penalty function replication file with delayed shocks.
I'm struggling to modify the code such that both first and second variable are restricted to 0 on impact.
I get that replacing 1 with 2 in ewise will impose zero restriction on variable 2. But I want to impose zero restriction on variable 1 and 2 both.

dec rect rirf(KZERO,nvar)
ewise rirf(i,j)=ix=%xt(impulses,i),ix(1,j)
compute forcedcols=i1x~sigmap*tr(rirf)
@forcedfactor(force=column) sigmad forcedcols ffactor
compute r2x=inv(sigmap)*%xsubmat(ffactor,1,nvar,%cols(forcedcols)+1,nvar)

If I restrict two variables to 0 , the parameter vector for (let's say) second identification would also change?
compute [vect] g1x=%fill(nvar-1,1,1.0) #1st identified shock
compute [vect] g2x=%fill(nvar-3,1,1.0) #2nd identified shock
Size of parameter for 2nd identified shock would then be nvar-4 for additional zero restriction.

Also, how should the 1st identified shock be modified such that the first shock also imposes zero constraints on variable 1 and 2?
dec rect rirf(KZERO,nvar)
ewise rirf(i,j)=ix=%xt(impulses,i),ix(1,j)
nonlin g1x
find(noprint,pmethod=genetic,piters=50,method=simplex) min func
compute v1x=%stereo(g1x)
compute func=UhligPenalty(v1x,KMIN,KMAX,||-3,+4||)
end find
compute i1x=sigmap*v1x
sak777
 
Posts: 1
Joined: Tue Feb 27, 2018 2:53 am


Return to VARs (Vector Autoregression Models)

Who is online

Users browsing this forum: No registered users and 2 guests

cron