Near VAR with Long Run restriction
Near VAR with Long Run restriction
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?
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
Re: Near VAR with Long Run restriction
Yes. With the near-VAR structure, you can't do unconditional draws for the covariance matrix.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?
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: 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?
There are other ways, but they usually require a bunch of different graphs. The HD done is the same as described atpfb382 wrote: c) Is there a different way of presenting the HDs? Dont really understand this decomposition presentation.
https://estima.com/docs/RATS%209%20User ... f#page=259
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 wrote: d) Have I done it otherwise ok, or is there a mistake in my estimation?
Re: Near VAR with Long Run restriction
Thanks Tom!
1)
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?
1)
So that means I just have to accumulate the Excel output manually, since it is obviously not readily accumulated in Excel ?!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.
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||)
}Re: Near VAR with Long Run restriction
Why would you accumulate them in Excel? They're already accumulated before being exported.pfb382 wrote:Thanks Tom!
1)So that means I just have to accumulate the Excel output manually, since it is obviously not readily accumulated in Excel ?!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: 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||)
}Re: Near VAR with Long Run restriction
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.Why would you accumulate them in Excel? They're already accumulated before being exported.
I then get following error message:{
if factor(3,4)<0.0
compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
## 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 (22.08 KiB) Viewed 17748 times
Re: Near VAR with Long Run restriction
You're using B where the other program used FACTOR.pfb382 wrote: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.Why would you accumulate them in Excel? They're already accumulated before being exported.
I then get following error message:{
if factor(3,4)<0.0
compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
## SX11. Identifier FACTOR is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>if factor(<<<<
Do you know why?
Regarding the other problem, update your procedures to get a newer @MCPROCESSIRF. (Help--Update Procedures operation).
Re: Near VAR with Long Run restriction
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!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).
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 (28.2 KiB) Viewed 17741 times
Re: Near VAR with Long Run restriction
You have to do the sign flip inside the loop as well.
Re: Near VAR with Long Run restriction
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?
Re: Near VAR with Long Run restriction
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).
Re: Near VAR with Long Run restriction
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
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
Re: Near VAR with Long Run restriction
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.
Re: Near VAR with Long Run restriction
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?{
if factor(3,4)<0.0
compute factor=factor*%diag(||1.0,1.0,1.0,-1.0||)
}
Re: Near VAR with Long Run restriction
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.