VARIRF—Impulse responses from VAR

Use this forum to post complete RATS "procedures". Please be sure to include instructions on using the procedure and detailed references where applicable.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

VARIRF—Impulse responses from VAR

Unread post by TomDoan »

@VARIRF organizes the graphs of an impulse response fuction from an already estimated VAR. Note that this just computes the IRF at the estimated coefficients; for error bands, you need to use @MonteVAR or the combination of @MCVARDODRAWS and @MCGRAPHIRF.

Detailed description
Last edited by TomDoan on Sat Jun 02, 2018 10:03 pm, edited 7 times in total.
Reason: Switch to description from HTML help
WALLE
Posts: 11
Joined: Thu Jul 21, 2011 12:24 pm

Re: VARIRF - Impulse responses from VAR

Unread post by WALLE »

Hello,

I am trying to estimate a 3 variable SVAR of the effects of oil price shocks on macroeconomic fluctuations as in "BJØRNLAND, H. C. (2000). The dynamic effects of aggregate demand, supply and oil price shocks - a comparative study. The Manchester School of Economic Studies, 68, pp. 578–607".

Identification is achieved by symmetry in the co-variance matrix which gives off six restrictions, one comes from assuming as in Blanchard and Quah that agg. demand has no LR effect on output however, real oil price shocks are allowed to affect output in the long run. The other two are zero short-run restrictions on oil prices which forces the contemporaneous effects of demand and supply shocks on real oil prices to be zero, allowing only oil price shocks will contemporaneously affect oil prices. However, after a period (one quarter), both demand and supply shocks are free to influence oil prices.

Following the RATS manual I came up with the following after the preliminary tests and all

Code: Select all

compute neqn = 3
compute nlags = 2
compute nsteps = 24
******************************************************************************************************
* ONE: SET UP VAR
*******************************************************************************************************
system(model=cansvar)
variables can_ur d_l_oilp_can d_l_can_gdp
lags 1 to nlags
det constant
end(system)

***********************************************************************************************
* TWO:ESTIMATE VAR
***********************************************************************************************
estimate(print,resids=varresidscan)
compute masums=inv(%varlagsums)
dec rect lr(3,3)
dec rect sr(3,3)
input sr
. . .
0 . 0
. . .
input lr
0 . .
. . .
. . .
@ShortAndLong(sr=sr,lr=lr,masum=masums) %sigma f
disp ###.### "Impact Responses" f
disp ###.### "Long run Responses" masums*f
@StructResids(factor=f) varresidscan 1970:01 2010:04 castrshocs

*********************************************************************************************************
*THREE: TO GENERATE IMPULSE RESPONSE FUNCTIONS
*********************************************************************************************************
dec vect[strings] shocklabels varlabels
compute shocklabels=||"Aggregate demand","Oil","Aggregate Supply"||
compute varlabels=||"Output","Oil Prices","Unemployment rate"||

dec vect[strings] shocklabels varlabels
@VARIRF(model=cansvar,steps=nsteps,factor=f,page=byshocks,$
  shocks=shocklabels,varlabels=varlabels)
@VARIRF(model=cansvar,steps=nsteps,factor=f,$
  shocks=shocklabels,varlabels=varlabels,page=byvariables)

**********************************************************************
*FOUR: IRF MATRICES
**********************************************************************
list ieqn = 1 to neqn
smpl 1 nsteps

declare rect[series] impblk(neqn,neqn)
declare vect[series] scaled(neqn)
declare vect[strings] implabel(neqn)
impulse(model=cansvar,result=impblk,noprint,$
  steps=nsteps,factor=f)

****************************************************************************************************************
*FIVE: GRAPHING RESPONSE OF ALL VARIABLES TO A SINGLE VARIABLE
****************************************************************************************************************
do i=1,neqn
  compute header="Plot of responses to "+implabel(i)
  do j=1,neqn
     set scaled(j) = (impblk(j,i))/sqrt(%sigma(j,j))
  end do j
  graph(header=header,key=below,klabels=implabel,number=0) neqn
  cards scaled(ieqn)
end do i

*******************************************************************************************************************
*SIX: GRAPHING RESPONSE OF A VARIABLE TO ALL SHOCKS
*******************************************************************************************************************
do i=1,neqn
  compute header="Plot of responses of "+implabel(i)
  graph(header=header,key=below,klabels=implabel,number=0) neqn
  cards impblk(i,ieqn)
end do i

*******************************************************************************************
*SEVEN: VARIANCE DECOMPOSITION
*******************************************************************************************
errors(factor=f,model=cansvar,steps=nsteps,window="CModel",$
   labels=||"Aggregate Demand","Oil","Aggregate Supply"||)
I have run the code however, I would like to ask the following questions:
1) Are my restrictions for identification as stated above correct with regards to my allocations of zeros in the LR and SR matrices?
2) My graphs are nameless when I try to carry out the procedure 5 & 6, is my procedure wrong and how do I rectify that?
3) In the structural example above, I see an accumulate = ||1,2,3|| what function does this perform?


Many thanks,
moderator
Site Admin
Posts: 269
Joined: Thu Oct 19, 2006 4:33 pm

Re: VARIRF - Impulse responses from VAR

Unread post by moderator »

"1) Are my restrictions for identification as stated above correct with regards to my allocations of zeros in the LR and SR matrices?"

It looks as if you have your dependent variables in the wrong order in the VAR setup. Everything else seems to match with a variables instruction which reads:

variables d_l_can_gdp d_l_oilp_can can_ur

"2) My graphs are nameless when I try to carry out the procedure 5 & 6, is my procedure wrong and how do I rectify that?"

You've declared the variable IMPLABEL, but you haven't stored any values in it. Use a COMPUTE instruction of the form:

compute implabel = ||"first", "second","third"||

to assign the labels you want to use. If you just want to use the existing variable names, you can use COMPUTE or EWISE along with functions to extract those names from the series themselves or from the model. For example:

ewise implabel(i)=%modellabel(model,i)

"3) In the structural example above, I see an accumulate = ||1,2,3|| what function does this perform?"

I believe that's explained in the procedure comments shown above--it allows you to have the procedure accumulate (compute a running sum) of the selected variables. In your case, you would probably want accum=||1,2|| since those variables enter the VAR in differenced form.

Regards,
Tom Maycock
Estima
WALLE
Posts: 11
Joined: Thu Jul 21, 2011 12:24 pm

Re: VARIRF - Impulse responses from VAR

Unread post by WALLE »

Thanks Tom,

I put in the code as advised below in step 3 and I obtained 6 graphs however when I tried to run steps 4,5 & 6, i get the following responses with no graphs:

##SX1. identifier IMPLABEL is already in use as a(n) RECTANGULAR [STRING]
subscripting error. Had array reference with(). Needed(INTEGER,INTEGER)
##SX27. Illegal combination of data types for operation
>>>>es of "+implabel(i)<<<<

How do I resolve this?

Many Thanks

Code: Select all

*********************************************************************************************************
*THREE: TO GENERATE IMPULSE RESPONSE FUNCTIONS
*********************************************************************************************************
dec vect[strings] shocklabels varlabels
compute shocklabels=||"Aggregate demand","Oil","Aggregate Supply"||
compute varlabels=||"Output","Oil Prices","Unemployment rate"||
[b]compute implabel=||"Aggregate demand","Oil","Aggregate Supply"||[/b]

dec vect[strings] shocklabels varlabels
@VARIRF(model=cansvar,steps=nsteps,factor=f,page=byshocks,$
  shocks=shocklabels,varlabels=varlabels)
@VARIRF(model=cansvar,steps=nsteps,factor=f,$
  shocks=shocklabels,varlabels=varlabels,page=byvariables)

**********************************************************************
*FOUR: IRF MATRICES
**********************************************************************
list ieqn = 1 to neqn
smpl 1 nsteps

declare rect[series] impblk(neqn,neqn)
declare vect[series] scaled(neqn)
declare vect[strings] implabel(neqn)
impulse(model=cansvar,result=impblk,noprint,$
  steps=nsteps,factor=f)
****************************************************************************************************************
*FIVE: GRAPHING RESPONSE OF ALL VARIABLES TO A SINGLE VARIABLE
****************************************************************************************************************
do i=1,neqn
  compute header="Plot of responses to "+implabel(i)
  do j=1,neqn
     set scaled(j) = (impblk(j,i))/sqrt(%sigma(j,j))
  end do j
  graph(header=header,key=below,klabels=implabel,number=0) neqn
  cards scaled(ieqn)
end do i
*******************************************************************************************************************
*SIX: GRAPHING RESPONSE OF A VARIABLE TO ALL SHOCKS
*******************************************************************************************************************
do i=1,neqn
  compute header="Plot of responses of "+implabel(i)
  graph(header=header,key=below,klabels=implabel,number=0) neqn
  cards impblk(i,ieqn)
end do i
moderator
Site Admin
Posts: 269
Joined: Thu Oct 19, 2006 4:33 pm

Re: VARIRF - Impulse responses from VAR

Unread post by moderator »

In this first section, you aren't declaring the type of IMPLABEL:

dec vect[strings] shocklabels varlabels
compute shocklabels=||"Aggregate demand","Oil","Aggregate Supply"||
compute varlabels=||"Output","Oil Prices","Unemployment rate"||
compute implabel=||"Aggregate demand","Oil","Aggregate Supply"||

So, the COMPUTE defaults to defining it as the more general RECTANGULAR of LABELS, rather than a VECTOR of LABELS. Then, later on, you are trying to (re) define it as a VECTOR:

declare vect[strings] implabel(neqn)

Hence the error message.

Unless you had something else in mind, you should just add IMPLABEL to that first DECLARE instruction:

dec vect[strings] shocklabels varlabels implabel

You can then omit the later DECLARE.

Regards,
Tom Maycock
Estima


Last bumped by TomDoan on Sat Jun 02, 2018 10:03 pm.
Post Reply