Graphing impulse responses w/ error bands to selected shocks

Questions and discussions on Vector Autoregressions
res84529
Posts: 13
Joined: Sat Aug 27, 2011 1:56 am

Graphing impulse responses w/ error bands to selected shocks

Unread post by res84529 »

Hello,

I want to graph the impulse response functions to selected shocks. But I find even the revised procedure @mcgraphirf doesn't offer such choice unless I choose "byshock" in the page option and stack the several columns of produced graphs in the word file, which seems awkward. Can you give me some advice to revise the @mcgraphirf procedure or other solutions so that I can graph the irfs with error bands to only selected shocks?

code file is attached
Attachments
unitshock_diffscale.txt
(4.97 KiB) Downloaded 961 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Graphing impulse responses w/ error bands to selected sh

Unread post by TomDoan »

The number of shocks you save in %%RESPONSES doesn't have to match with the number of variables. The following, for instance, will save only the first two---it uses %xsubmat to take the first two columns out of the step j matrix of impulse responses.

Code: Select all

   dim %%responses(draw)(nvar*2,nstep)
   compute weights(draw)=weight
   ewise %%responses(draw)(i,j)=ix=%vec(%xsubmat(%xt(impulses,j),1,nvar,1,2)),ix(i)
res84529
Posts: 13
Joined: Sat Aug 27, 2011 1:56 am

To several shocks which are not consecutive in order

Unread post by res84529 »

Hi, Tom!

Thank you very much for your quick reply! I really appreciate that!

The solution works if I want to graph the two columns which are consecutive in the order. But what is needed is to stack the responses to the 3rd, 6th, and 7th shocks only in one graph without adding responses to other shocks. Could you still give me some suggestions on how to do this?

Thank you!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Graphing impulse responses w/ error bands to selected sh

Unread post by TomDoan »

That would be done with

Code: Select all

   dim %%responses(draw)(nvar*3,nstep)
   compute weights(draw)=weight
   ewise %%responses(draw)(i,j)=xt=%xt(impulses,j),ix=%vec(%xcol(xt,3)~%xcol(xt,6)~%xcol(xt,7)),ix(i)
res84529
Posts: 13
Joined: Sat Aug 27, 2011 1:56 am

Some remaining questions

Unread post by res84529 »

Hi Tom,

Thank you so much for your help!

I also tried horizontal concatenation with the following code before I looked at your answer:
ewise %%responses(draw)(i,j)=ix=%vec(%xsubmat(%xt(acumirf,j),1,nvar,3,3)~%xsubmat(%xt(acumirf,j),1,nvar,6,7)),ix(i)

It works. In addition, I'm confused about the meaning of the part of the code which is originally from UG p. 498:
impulses((i-1)/nvar+1,%clock(i,nvar))(j)

Could you please explain to me what's the meaning of "(i-1)/nvar+1,%clock(i,nvar)"? what's the use of it?
In addition, why should we repeat with another ix(i) after already defining it in the ewise instruction above since there's no such requirement in the standard ewise instruction setup?

Best Regards
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Some remaining questions

Unread post by TomDoan »

res84529 wrote:Hi Tom,

Thank you so much for your help!

I also tried horizontal concatenation with the following code before I looked at your answer:
ewise %%responses(draw)(i,j)=ix=%vec(%xsubmat(%xt(acumirf,j),1,nvar,3,3)~%xsubmat(%xt(acumirf,j),1,nvar,6,7)),ix(i)

It works. In addition, I'm confused about the meaning of the part of the code which is originally from UG p. 498:
impulses((i-1)/nvar+1,%clock(i,nvar))(j)

Could you please explain to me what's the meaning of "(i-1)/nvar+1,%clock(i,nvar)"? what's the use of it?
The set of impulse responses would best be represented as a three dimensional array (step, shock, target variable) and we need one matrix like that per draw, so you really would want a four dimensional array. Lacking that, you need to map everything down to fewer dimensions. In this case, it's a VECTOR (over the draws) of RECT, which is a two-dimensional array with steps in the columns and shocks x target variables in the rows. With the combined subscripts blocked by shocks, the (i-1)/nvar+1 maps the combined subscripts to the target variable and %clock(i,nvar) to the shock. The coding for this in the RATS v8 UG is the simpler:

ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)

which does exactly the same thing.
res84529 wrote: In addition, why should we repeat with another ix(i) after already defining it in the ewise instruction above since there's no such requirement in the standard ewise instruction setup?

Best Regards
EWISE has an internal loop over i and j and needs to have an expression which evaluates to a single number. The IX calculation creates a VECTOR based upon desired value of the J subscript (which is the step); IX(I) then takes the Ith element out of that to make %%responses(draw)(i,j)
Post Reply