Uhlig JME 2005 Sign-Restricted IRF's for VAR

Use this forum for posting example programs or short bits of sample code.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by TomDoan »

uhligjme2005.zip is a set of replication files for Uhlig(2005), "What are the effects of monetary policy on output? Results from an agnostic identification procedure", Journal of Monetary Economics, vol 52, no 2, 381-419. This extracts a monetary policy shock from a six-variable VAR based upon sign-restrictions on the responses of the variables.

The methods used in this are described in detail as part of the Vector Autoregressions e-course.

Detailed description
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Understanding part of the Uhlig Code

Unread post by RK2509 »

Hi,

I am working on sign restrictions. I am trying to understand the following part of the code:

Code: Select all

do k=1,KMAX+1
      compute ik=%xt(impulses,k)*a
      if ik(4)<0.or.ik(3)>0.or.ik(2)>0.or.ik(5)>0
         goto reject
   end do k
   gset oneresp 1 nsteps = %xt(impulses,t)*a
   do i=1,nvar
      set maxi(i) 1 nsteps = %max(oneresp{0}(i),maxi(i))
      set mini(i) 1 nsteps = %min(oneresp{0}(i),mini(i))
   end do i
   compute accept=accept+1
   compute %pt(impacts,accept,atilde*a)
   infobox(current=accept)
   if accept==nkeep
      break
:reject
end do draws
infobox(action=remove)
disp "***Accepted Draws***" accept "on" draws "attempts".
I have read the paper of Uhlig, but I am unable to understand the full code. I do get this part that:

Code: Select all

do k=1,KMAX+1
      compute ik=%xt(impulses,k)*a
      if ik(4)<0.or.ik(3)>0.or.ik(2)>0.or.ik(5)>0
         goto reject
   end do k
But after that, I am stuck.

Code: Select all

   gset oneresp 1 nsteps = %xt(impulses,t)*a
   do i=1,nvar
      set maxi(i) 1 nsteps = %max(oneresp{0}(i),maxi(i))
      set mini(i) 1 nsteps = %min(oneresp{0}(i),mini(i))
   end do i
   compute accept=accept+1
   compute %pt(impacts,accept,atilde*a)
   infobox(current=accept)
   if accept==nkeep
      break
:reject
end do draws
infobox(action=remove)
disp "***Accepted Draws***" accept "on" draws "attempts".
My research restriction is that a contractionary policy does not lead to an increase in inflation (CPI)/GDP or decrease in interest rate.

How do I do it. Could you please help me. Many Thanks
Kind Regards
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by TomDoan »

First of all, have you read the "detailed description" above? It explains how the restrictions are input. Unless you know where the variables are in the model, it's impossible to tell how to describe the restrictions.

The section of code that you're examining is just looking at the outer limits of the shocks that meet the criterion (so it's used after the shock has been determined to meet the restrictions). That was probably more interesting in the original paper than it would be now.
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by RK2509 »

Thank you so much Tom.

So its plotting the maximum and minimum of the impulse responses that satisfy the restrictions.
So now if I have to replicate the same for my work, i.e. in my restrictions I basically apply to this part of the code right? I will make the necessary changes according to my ordering of variables...

if atest(4)<0
compute a=-1.0*a

do k=1,KMAX+1
compute ik=%xt(impulses,k)*a
if ik(4)<0.or.ik(3)>0.or.ik(2)>0.or.ik(5)>0
goto reject
end do k

I believe this is the main restriction that I need to change according to my variables. Is that correct?

Many Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by TomDoan »

Correct. That's the only place where the restrictions enter.
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by RK2509 »

Hi Tom,

So I modified the Uhlig code according to my variable..But I am not getting any accepted draws.. could you see if this code is fine?

Code: Select all

*
CALENDAR(q) 1996:1
open data lkdata1996.xls
data(format=xls,org=cols) 1996:1 2013:4 	GDP	INR	CPI FoodPrice nms REER
*
set lnrgdp = log(gdp/cpi)*100
set lncpi   = log(cpi)*100.0
set lnrms = log(nms/cpi)*100.0
set lnreer = log(reer)*100.0
set lnfoodprice = log(FoodPrice)*100


compute nvar = 6
 declare vector[series] depvar(6)
labels depvar(1) depvar(2) depvar(3) depvar(4) depvar(5) depvar(6)
# 'Real GDP' 'Consumer Price Index' ' Food Price'  'Interest Rate' 'Real exchange Rate' 'Real Money' 
smpl 1996:1 2013:4
inquire(smpl) nbeg nend
set depvar(1) 1996:1 nend = lnrgdp
set depvar(2) 1996:1 nend = lncpi
set depvar(3) 1996:1 nend = inr
set depvar(4) 1996:1 nend = lnfoodprice
set depvar(5) 1996:1 nend = lnreer
set depvar(6) 1996:1 nend = lnrms
set trend = t
inquire(seasonal) sfreq
compute sfreqreg = sfreq
seasonal season


************************************************************************************************
* VAR estimation
system(model=sixvar)
variables depvar
lags 1 to 12
det constant trend season{-sfreq to -2}
end(system)
estimate(noprint)

compute nvar  =6
compute nsteps=15
compute nkeep =1000
compute n2    =50000
compute KMAX  =5
*
* Compute standard impulse response functions
*
compute atilde=%decomp(%sigma)
impulse(model=sixvar,steps=nsteps,results=impulses,$
  factor=atilde,noprint)
*
dec vect[series] mini(nvar) maxi(nvar)
dec series[vect] oneresp
dec vect a(nvar) atest ik
dec vect[series] impacts(nvar)

**********************************************************************************************************

do i=1,nvar
   set impacts(i) 1 nkeep = %na
end do i
*
do i=1,nvar
   set mini(i) 1 nsteps = 1.e+10
   set maxi(i) 1 nsteps = -1.e+10
end do i
*
compute accept=0
infobox(action=define,progress,lower=1,upper=nkeep) $
   "Monte Carlo Integration"
do draws=1,n2
   *
   *  Take a draw from the unit sphere.
   *
   compute a=%ransphere(nvar)
   *
   *  Transform back to the original variable space
   *
   compute atest=atilde*a
   *
   *  Flip the sign if the inr shock is negative
   *
   if atest(4)<0
      compute a=-1.0*a

do k=1,KMAX+1
      compute ik=%xt(impulses,k)*a
      if ik(4)<0.or.ik(3)>0.ik(2)>0.or.ik(5)>0
         goto reject
   end do k
   gset oneresp 1 nsteps = %xt(impulses,t)*a
   do i=1,nvar
      set maxi(i) 1 nsteps = %max(oneresp{0}(i),maxi(i))
      set mini(i) 1 nsteps = %min(oneresp{0}(i),mini(i))
   end do i
   compute accept=accept+1
   compute %pt(impacts,accept,atilde*a)
   infobox(current=accept)
   if accept==nkeep
      break
:reject
end do draws
infobox(action=remove)
disp "***Accepted Draws***" accept "on" draws "attempts"
My restriction is that as interest rates fall(expansionary monetary policy), money supply and prices go up. As roi rises(contractionary monetary policy, the opposite happens). I think I am going wrong somewhere. I would be really grateful for any help.
Many Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by TomDoan »

variable 4 is food prices, not interest rates.
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by RK2509 »

Oh ok , yeah I see the mistake..Many Many Thanks Tom. !!
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by RK2509 »

Hi Tom,

I have another question in sign restrictions. I need to multiply a scalar lambda with the impulse response of third variable to 4th shock, (i.e. foodprice to inr shock). I was thinking how to multiply the elements of lambda with the impulse(3,4).


Initially when I started off with short run contemporaneous restrictions this is what I did

Code: Select all

dec rect[series] z(N,1)
do i=1,N
set z(i,1) = lambda(i,1)*impulses(3,4)
end do i
However, I don't know how to do this in sign restrictions.

Code: Select all

spgraph(vfields=3,hfields=2,$
  footer="Impulse Responses with Pure-Sign Approach")
do i=1,nvar
   smpl 1 accept
   do k=1,nstep
      set work = goodresp(t)(k,i)
      compute frac=%fractiles(work,||.16,.84||)
      compute lower(k)=frac(1)
      compute upper(k)=frac(2)
      compute resp(k)=%avg(work)
   end do k
   *
   smpl 1 nstep
   graph(ticks,number=0,picture="##.##",$
      header="Impulse Responses for "+vl(i)) 3
   # resp
   # upper / 2
   # lower / 2
end do i
*
I am unable to understand where should I multiply lambda with to get the scaled responses of third variable to 4th shock.

Many Thanks Tom for all your help.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by TomDoan »

Assuming lambda is positive, you can do it pretty much any time since scaling will have no effect on the signs. If you just change

set work = goodresp(t)(k,i)

to

set work = mylambda*goodresp(t)(k,i)

that will take care of it.
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by RK2509 »

The thing is I have 72 individual food prices and for each of these I want to get the IRF's. So I am multiplying the LATENT FACTOR lambda(there are 72 of these) with the main IRF of (3,4) the third variable to fourth shock.(Food Price to inr shock)

is this right?

So initially I was doing in short run restrictions.

dec rect[series] z(N,1)
do i=1,N
set z(i,1) = lambda(i,1)*impulses(3,4)
end do i

I have 72 Z's. In sign restrictions how should I do it? Should I go ahead and just write set work = lambda(i,1)*goodresp(t)(k,i)
Am not sure.
Many Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by TomDoan »

I'm confused. Do you have a 72 variable VAR?
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by RK2509 »

I have a 6 variable VAR-GDP, CPI, FOOD PRICE, INTEREST RATE, CONSUMER EXPENDITURE AND MONEY SUPPLY. THE FOOD PRICE that I am using here is what I get after getting a latent factor from the list of 72 food prices through PCA . I call that F(1). I use F(1) as my food price in the 6 Variable VAR. I then use sign restrictions in the 6 Variable VAR. I get a set of draws that satisfy my sign restrictions. One of them is the IRF of food price(F(1) to inr shock.

I then have to multiply each of the lamda's (72 of them)with the IRF of food price to inr shock. I AM STUCK AT THIS STEP
Many Thanks Tom for all your help.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by TomDoan »

set work = goodresp(t)(k,3)

will get you the responses of food price, so it sounds like you just want to scale that by a different lambda so

set work = lambda(i,1)*goodresp(t)(k,3)

will give you the response of component i. I'm not sure how you plan to present that, but you would just wrap that (and the calculations of the response and upper and lower bound) inside a DO I loop running over your 72 components.
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Uhlig JME 2005 Sign-Restricted IRF's for VAR

Unread post by RK2509 »

Thank you so much Tom. Let me try. I am also wondering how to graph them i.e. present them.
Post Reply