Near VAR with Long Run restriction

Questions and discussions on Vector Autoregressions
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Near VAR with Long Run restriction

Unread post by pfb382 »

Hi,

I am completely new to RATS, but I have tried my best to set up a near VAR with long run restrictions - I am interested in the (accumulated) IRF, FEVD, and ideally the HD. See the code and data attached.

a) is it correct that I have to work with Gibbs Sampling and I cant use Monte Carlo for my error bands in a Near Var?

b) is there a way I can accumulate my shocks before doing my error band sampling or is the accumulate option in the MC function OK? I am worried that the Confidence bands also just get accumulated - which should not be. And why doesn't my IRF- Excel output present the accumulated shock?

c) Is there a different way of presenting the HDs? Dont really understand this decomposition presentation.

d) Have I done it otherwise ok, or is there a mistake in my estimation?
Attachments
Book1.xls
data
(23 KiB) Downloaded 732 times
blockexo.RPF
code
(3.44 KiB) Downloaded 962 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Near VAR with Long Run restriction

Unread post by TomDoan »

pfb382 wrote:Hi,

I am completely new to RATS, but I have tried my best to set up a near VAR with long run restrictions - I am interested in the (accumulated) IRF, FEVD, and ideally the HD. See the code and data attached.

a) is it correct that I have to work with Gibbs Sampling and I cant use Monte Carlo for my error bands in a Near Var?
Yes. With the near-VAR structure, you can't do unconditional draws for the covariance matrix.
pfb382 wrote: b) is there a way I can accumulate my shocks before doing my error band sampling or is the accumulate option in the MC function OK? I am worried that the Confidence bands also just get accumulated - which should not be. And why doesn't my IRF- Excel output present the accumulated shock?
You don't accumulate the error bands, but the error bands are of the accumulated responses. The Excel output and graphs seem to match from what I can see. Note that response(i,j) is the response of i to shock j.
pfb382 wrote: c) Is there a different way of presenting the HDs? Dont really understand this decomposition presentation.
There are other ways, but they usually require a bunch of different graphs. The HD done is the same as described at

https://estima.com/docs/RATS%209%20User ... f#page=259
pfb382 wrote: d) Have I done it otherwise ok, or is there a mistake in my estimation?
The only thing obvious is that you typically don't associate the shocks in a LR SVAR one-to-one with the variables (as you have your graph labels).
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Near VAR with Long Run restriction

Unread post by pfb382 »

Thanks Tom!

1)
You don't accumulate the error bands, but the error bands are of the accumulated responses. The Excel output and graphs seem to match from what I can see. Note that response(i,j) is the response of i to shock j.
So that means I just have to accumulate the Excel output manually, since it is obviously not readily accumulated in Excel ?!

2) I read in another thread that you can restrict the demand shock to have a positive effect on output. For me shock 4 on variable 3. I am refering to the code below ( from: https://estima.com/forum/viewtopic.php?f=4&t=1403 ) How would I have to implement that into my near-VAR model estimated with SUR?

Code: Select all

system(model=bqmodel)
var rgdp_ca inf_ca
lags 1 to 2
det constant
end(system)

estimate(noprint,resids=resids)
compute factor=%bqfactor(%sigma,%varlagsums)
{
if factor(1,2)<0.0
compute factor=factor*%diag(||1.0,-1.0||)
}
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Near VAR with Long Run restriction

Unread post by TomDoan »

pfb382 wrote:Thanks Tom!

1)
You don't accumulate the error bands, but the error bands are of the accumulated responses. The Excel output and graphs seem to match from what I can see. Note that response(i,j) is the response of i to shock j.
So that means I just have to accumulate the Excel output manually, since it is obviously not readily accumulated in Excel ?!
Why would you accumulate them in Excel? They're already accumulated before being exported.
pfb382 wrote: 2) I read in another thread that you can restrict the demand shock to have a positive effect on output. For me shock 4 on variable 3. I am refering to the code below ( from: https://estima.com/forum/viewtopic.php?f=4&t=1403 ) How would I have to implement that into my near-VAR model estimated with SUR?

Code: Select all

system(model=bqmodel)
var rgdp_ca inf_ca
lags 1 to 2
det constant
end(system)

estimate(noprint,resids=resids)
compute factor=%bqfactor(%sigma,%varlagsums)
{
if factor(1,2)<0.0
compute factor=factor*%diag(||1.0,-1.0||)
}
{
if factor(3,4)<0.0
   compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Near VAR with Long Run restriction

Unread post by pfb382 »

Why would you accumulate them in Excel? They're already accumulated before being exported.
thats the thing, they are not accumulated in my Excel output even though I asked it too, see file attached for output example of a supply shock to bwdi. Clearly not accumulated.
{
if factor(3,4)<0.0
compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
I then get following error message:
## SX11. Identifier FACTOR is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>if factor(<<<<

Do you know why?

Thats the code I am running:

Code: Select all

* BURUNDI
compute lags=1         ;*Number of lags
compute nsteps=5     ;*Number of response steps
compute nburn =5000    ;*Burn-in draws
compute ndraws=25000   ;*Keeper draws
*
open data
calendar 1971 1 1
all 2015:1
data(format=xls,org=col) 1971:1 2015:1 world	tot bwdi rer binf
*
*MODEL
equation for1 world
# world{1 to lags} tot{1 to lags} constant
equation for2 tot
# world{1 to lags} tot{1 to lags} constant
equation dom1 bwdi
# world{1 to lags} tot{1 to lags} bwdi{1 to lags} binf{1 to lags} constant
equation dom2 binf
# world{1 to lags} tot{1 to lags} bwdi{1 to lags} binf{1 to lags} constant
*
* Create the model
*
group surmodel for1 for2 dom1 dom2
compute nvar=%modelsize(surmodel)
*
*
**SURGIbbs set-up
@SURGibbsSetup surmodel
sur(model=surmodel, iter=20,outsigma=%sigmaAtBeta)
compute ntotal=%nreg
compute bdraw=%beta
compute wishdof=%nobs
*
*
**Short run and long run restrictions
dec rect lr(4,4) sr(4,4)
input sr
. . . .
. . . .
. . . .
. . . .

**
input lr
. 0 0 0
. . 0 0
. . . 0
. . . .


@shortandlong(sr=sr,lr=lr,masums=inv(%modellagsums(surmodel)),factor=b) %sigmaAtBeta %sr %lr
if factor(3,4)<0.0
   compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
*
**Impulse responses and Error Bands
declare vect[rect] %%responses(ndraws)
*
infobox(action=define,progress,lower=-nburn,upper=ndraws) $
    "Gibbs Sampling"
do draw=-nburn,ndraws
   *
   * Compute covariance matrix of residuals at the current beta
   *
   compute covmat=SURGibbsSigma(bdraw)
   *
   * Do a draw for the precision matrix conditional on beta
   *
   compute hdraw=%ranwishartf(%decomp(inv(covmat)),wishdof)
   *
   * Compute the required information with the interaction between
   * the precision matrix and the data
   *
   @SURGibbsDataInfo hdraw hdata hbdata
   *
   * Draw coefficients given the precision matrix hdraw
   *
   compute bdraw=%ranmvposthb(hdata,hbdata)
   infobox(current=draw)
   if draw<=0
      next
   *
   * Do the bookkeeping here.
   *
compute sigmad=inv(hdraw)
@ShortAndLong(lr=lr,sr=sr,masum=inv(%modellagsums(surmodel))) sigmad b

impulse(noprint,model=surmodel,factor=b,steps=nsteps,flatten=%%responses(draw))

end do draw
infobox(action=remove)

******************* IRFs and FEVDs **********************************
@MCProcessIRF(model=surmodel,center=mean,accumulate=||3,4||,percent=||.16,.84||,IRF=irf,UPPER=upper,LOWER=lower)
copy(format=xls,org=columns) / irf lower upper
Attachments
3,3.JPG
3,3.JPG (22.08 KiB) Viewed 17748 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Near VAR with Long Run restriction

Unread post by TomDoan »

pfb382 wrote:
Why would you accumulate them in Excel? They're already accumulated before being exported.
thats the thing, they are not accumulated in my Excel output even though I asked it too, see file attached for output example of a supply shock to bwdi. Clearly not accumulated.
{
if factor(3,4)<0.0
compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
I then get following error message:
## SX11. Identifier FACTOR is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>if factor(<<<<

Do you know why?
You're using B where the other program used FACTOR.

Regarding the other problem, update your procedures to get a newer @MCPROCESSIRF. (Help--Update Procedures operation).
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Near VAR with Long Run restriction

Unread post by pfb382 »

You're using B where the other program used FACTOR.

Regarding the other problem, update your procedures to get a newer @MCPROCESSIRF. (Help--Update Procedures operation).
The excel output is correct now. With "b" the code also runs through, BUT it does not change the IRF of a demand shock on output as wanted to make the effect positive. Could you help me out there again. Then I will be satisfied. Thanks a lot for all your help!

Code: Select all

* BURUNDI
compute lags=1         ;*Number of lags
compute nsteps=5     ;*Number of response steps
compute nburn =5000    ;*Burn-in draws
compute ndraws=25000   ;*Keeper draws
*
open data
calendar 1971 1 1
all 2015:1
data(format=xls,org=col) 1971:1 2015:1 world	tot bwdi binf
*
*MODEL
equation for1 world
# world{1 to lags} tot{1 to lags} constant
equation for2 tot
# world{1 to lags} tot{1 to lags} constant
equation dom1 bwdi
# world{1 to lags} tot{1 to lags} bwdi{1 to lags} binf{1 to lags} constant
equation dom2 binf
# world{1 to lags} tot{1 to lags} bwdi{1 to lags} binf{1 to lags} constant
*
* Create the model
*
group surmodel for1 for2 dom1 dom2
compute nvar=%modelsize(surmodel)
*
*
**SURGIbbs set-up
@SURGibbsSetup surmodel
sur(model=surmodel, iter=20,outsigma=%sigmaAtBeta)
compute ntotal=%nreg
compute bdraw=%beta
compute wishdof=%nobs
*
*
**Short run and long run restrictions
dec rect lr(4,4) sr(4,4)
input sr
. . . .
. . . .
. . . .
. . . .

**
input lr
. 0 0 0
. . 0 0
. . . 0
. . . .


@shortandlong(sr=sr,lr=lr,masums=inv(%modellagsums(surmodel)),factor=b) %sigmaAtBeta %sr %lr
{
if b(3,4)<0.0
compute b=b*%diag(||1.0,1.0,1.0,-1.0||)
}
*
**Impulse responses and Error Bands
declare vect[rect] %%responses(ndraws)
*
infobox(action=define,progress,lower=-nburn,upper=ndraws) $
    "Gibbs Sampling"
do draw=-nburn,ndraws
   *
   * Compute covariance matrix of residuals at the current beta
   *
   compute covmat=SURGibbsSigma(bdraw)
   *
   * Do a draw for the precision matrix conditional on beta
   *
   compute hdraw=%ranwishartf(%decomp(inv(covmat)),wishdof)
   *
   * Compute the required information with the interaction between
   * the precision matrix and the data
   *
   @SURGibbsDataInfo hdraw hdata hbdata
   *
   * Draw coefficients given the precision matrix hdraw
   *
   compute bdraw=%ranmvposthb(hdata,hbdata)
   infobox(current=draw)
   if draw<=0
      next
   *
   * Do the bookkeeping here.
   *
compute sigmad=inv(hdraw)
@ShortAndLong(lr=lr,sr=sr,masum=inv(%modellagsums(surmodel))) sigmad b
impulse(noprint,model=surmodel,factor=b,steps=nsteps,flatten=%%responses(draw))

end do draw
infobox(action=remove)

******************* IRFs and FEVDs **********************************
@MCGraphIRF(model=surmodel,center=mean,accumulate=||3,4||,percent=||.025,.16,.84,.975||,page=all)
@MCProcessIRF(model=surmodel,center=mean,accumulate=||3,4||,percent=||.16,.84||,IRF=irf,UPPER=upper,LOWER=lower)
copy(format=xls,org=columns) / irf lower upper
Attachments
IRF 3,4.JPG
IRF 3,4.JPG (28.2 KiB) Viewed 17741 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Near VAR with Long Run restriction

Unread post by TomDoan »

You have to do the sign flip inside the loop as well.
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Near VAR with Long Run restriction

Unread post by pfb382 »

Perfect! Thanks. Now when I want to look at unit shocks instead of SD shocks, I read that I have to insert: "compute shocks=%ddivide(b,%xdiag(b))" ,where b is my factor. Is that correct and more important where exactly do I have to insert it into my code?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Near VAR with Long Run restriction

Unread post by TomDoan »

First, I'm not sure that's a good idea. (The fact that it's been done doesn't make it a good idea). The shocks don't correspond 1-1 to variables, so scaling to unit impacts on the diagonal doesn't really make sense. Also, scaling to unit diagonals may be incompatible with scaling to create a positive impact off the diagonal. You would put it where the sign flip code is (the sign flip code will have no effect).
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Near VAR with Long Run restriction

Unread post by pfb382 »

OK, I wont do the unit shocks then. I have one more question that is not necessarily RATS related, but I was unable to find the solution anywhere else. Would be grateful if you can help me out here as well.

When I compare the IRFs of different countries. Do I need to calculate the correlation of the the accumulated IRFs or of the growth ratas (original IRFs)? THANKS A MILLION
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Near VAR with Long Run restriction

Unread post by TomDoan »

Most reports will be in terms of the (log) levels of macro data (i.e. response of log GDP, log prices, log money, etc.) So if you've estimated the VAR in growth rates, you would generally want the accumulated responses of any series that was transformed that way.
pfb382
Posts: 22
Joined: Fri Apr 14, 2017 5:25 pm

Re: Near VAR with Long Run restriction

Unread post by pfb382 »

{
if factor(3,4)<0.0
compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
Tom, this sign flipping might give my demand shock the positive effect on output , but it also flipps the positive demand shock to a negative response in inflation. Thats not really good. How to deal with that?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Near VAR with Long Run restriction

Unread post by TomDoan »

You would have to change your model, probably to some combination of short-and-long-run restrictions rather than relying solely on long-run restrictions. Long-run restrictions say nothing about the impacts and you can only control one sign in a column.
Post Reply