Page 1 of 1

Generalized Impulse Responses

Posted: Thu Jan 12, 2012 7:37 am
by nazif
Dear Tom,
Thank you for your suggestions on the linear generalized impulse responses. Actually this work is under review process and one of the reviewers asks us to create the nonlinear impulse responses with sd error bands based on the paper of Koop et al. "Koop, G., M.H. Pesaran, and S. Potter (1996). Impulse Response Analysis in Nonlinear Multivariate Models, Journal of Econometrics 4, 119-147." But this code only allows us to produce linear irfs. I know there is a nonlinear code sms_5_2.rpf in the forum based on the paper of Balke and Fomby (1997).

http://www.estima.com/forum/viewtopic.p ... nses#p3402

But I know it is for a bivariate model and MCDORAWS only produce the linear impulse responses. I would be very glad if help me to modify the above code in order to obtain nonlinear irfs with error bands?
Thanks for your help.
Nazif

Re: Generalized Impulse Responses

Posted: Fri Jan 13, 2012 11:10 am
by TomDoan
The GIRF's for a switching model are very different from the much simpler GIRF's for a linear model.

Compared to the Balke-Fomby model, yours is actually simpler (though bigger) because your switching criterion depends upon a series that's directly in the VAR rather than a series that has to be derived from them. This is the Balke-Fomby code with the hard numbers for the number of regimes and number of variables replaced by integer variables.

Code: Select all

compute nvar=2
compute nregime=3
*
system(model=basevecm)
variables dff ddr
lags 1
det constant spread{1}
end(system)
*
dec rect[frml] tvecfrml(nvar,nregime)
do i=1,nregime
   estimate(smpl=(switch(t)==i))
   do j=1,nvar
      frml(equation=%modeleqn(basevecm,j)) tvecfrml(j,i)
   end do j
end do i
*
frml(identity) ffid fedfunds = fedfunds{1}+dff
frml(identity) drid mdiscrt  = mdiscrt{1}+ddr
frml(identity) spid spread   = fedfunds-mdiscrt
*
dec vect[frml] switchf(nvar)
do j=1,nvar
   frml switchf(j) %modeldepvars(basevecm)(j) = tvecfrml(&j,switch(t))
end do j
*
* You have to list the switchf's separately on the GROUP instruction
*
group tvecm switchf(1) switchf(2) ffid drid spid
In your model, you don't need the FFID, DRID and SPID formulas, since those are to compute forecasts of the SPREAD from the differences in their components.

Re: Generalized Impulse Responses

Posted: Fri Jan 13, 2012 11:38 am
by nazif
Dear Doan,
Thanks for the useful information. How can I compute irfs from the above model? Can I use impulse instruction or do I have to adjust Balke & Fomby Code to my study?
Nazif

Re: Generalized Impulse Responses

Posted: Fri Jan 13, 2012 12:39 pm
by TomDoan
nazif wrote:Dear Doan,
Thanks for the useful information. How can I compute irfs from the above model? Can I use impulse instruction or do I have to adjust Balke & Fomby Code to my study?
Nazif
You would have to adjust the Balke-Fomby code. It's a non-linear model, so the responses depend upon the initial conditions.

Re: Generalized Impulse Responses

Posted: Sun Jan 15, 2012 1:08 pm
by nazif
TomDoan wrote:
nazif wrote:Dear Doan,
Thanks for the useful information. How can I compute irfs from the above model? Can I use impulse instruction or do I have to adjust Balke & Fomby Code to my study?
Nazif
You would have to adjust the Balke-Fomby code. It's a non-linear model, so the responses depend upon the initial conditions.
Dear Doan
I have emailed my program files to you with my licence information.
Thanks for help.

Re: Generalized Impulse Responses

Posted: Mon Jan 16, 2012 11:52 am
by nazif
Dear Doan,
I have changed switching variable but still get the following error in the loop

dec vect[frml] switchf(nvar)
do j=1,nvar
frml switchf(j) %modeldepvars(basevecm)(j) = tvecfrml(j,switch(t))
end do j

## SX22. Expected Type INTEGER, Got REAL Instead
>>>>ecfrml(j,switch(t))<<<<

Re: Generalized Impulse Responses

Posted: Mon Jan 16, 2012 12:35 pm
by TomDoan
In the original Balke-Fomby program:

Code: Select all

dec frml[int] switch
frml switch = 1+fix((spread{1}>=lower)+(spread{1}>upper))
In adapting that, you're missing the declaration as a FRML[INT] and the FIX function in the definition.

Re: Generalized Impulse Responses

Posted: Mon Jan 16, 2012 12:45 pm
by nazif
Dear Tom

This time I get the following error, and do you think that the posted balke codes calculate nonlinear girfs?

## MAT2. Matrices with Dimensions 20 x 20 and 2 x 1 Involved in %PSDFACTOR Operation

Code: Select all

* SMS_5_2.RPF
* Switching Models and Structural Breaks
* Example 5.2
*
* Based upon Balke and Fomby(1997), "Threshold Cointegration,"
* International Economic Review, vol 38, no 3, 627-45.
*
* Data file is a reconstruction.
*
* This estimates the thresholds using the bivariate likelihood, computes
* an eventual forecast function and GIRF.
*
open data montra_2011_4.xls
calendar(m) 1986
data(format=xls,org=columns) 1986:1 2010:11
*
set thresh = INTBRATE{1}
dec frml[int] switch
frml switch = 1+fix(INTBRATE{1}>=0.228)
*
* Estimate the model at the best breaks to get the covariance matrix.
*
sweep(group=switch(t))
# LIP{1 to 4} LCPI{1 to 4} INTBRATE{1 to 4} LRERCPI_SA{1 to 4} LCRE{1 to 4}
# constant lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
compute tvecmsigma=%sigma
*

*
compute nvar=5
compute nregime=2
*
system(model=basevecm)
variables LIP LCPI INTBRATE LRERCPI_SA LCRE
lags 1 to 4
det constant lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
end(system)
dec rect[frml] tvecfrml(nvar,nregime)
do i=1,nregime
   estimate(smpl=(switch(t)==i))
   do j=1,nvar
      frml(equation=%modeleqn(basevecm,j)) tvecfrml(j,i)
   end do j
end do i
*
dec vect[frml] switchf(nvar)
do j=1,nvar
   frml switchf(j) %modeldepvars(basevecm)(j) = tvecfrml(j, switch(t))
end do j
* My endogenous variables are LIP LCPI INTBRATE LRERCPI_SA LCRE
group tvecm switchf(1) switchf(2) switchf(3) switchf(4) switchf(5)  

*
* Eventual forecast function, starting with 2003:4 data (Post-inflation targeting period).
*
forecast(model=tvecm,from=2003:4,steps=24,results=eff)
graph(footer=$
   "Eventual Forecast Function for Credit, starting at 2003:4")
# eff(5)
graph(footer=$
   "Eventual Forecast Function for CPI, starting at 2003:4")
# eff(2)
*
* GIRF starting in 1998:3 for a one s.d. shock to DR correlated with FF
* using the estimated covariance matrix. (1969:3 has values for both
* rates which are close to the average for the full period).
*
compute ndraws=5000
compute baseentry=1998:3
compute nsteps   =24
*
dec vect[series] fshocks(5) girf(5)
dec series[vect] bishocks
dec vect ishocks
*
smpl baseentry baseentry+(nsteps-1)
do i=1,5
   set girf(i) = 0.0
end do i
*
compute fsigma=%psdfactor(tvecmsigma,||2,1||)
*
do draw=1,ndraws
   gset bishocks = %ranmvnormal(fsigma)
   set fshocks(1) = bishocks(t)(1)
   set fshocks(2) = bishocks(t)(2)
   set fshocks(3) = bishocks(t)(3)
   set fshocks(4) = bishocks(t)(4)
   set fshocks(5) = bishocks(t)(5)

   forecast(paths,model=tvecm,results=basesims)
   # fshocks
   compute ishock=fsigma(5,5)
   compute ishocks=inv(fsigma)*bishocks(baseentry)
   compute ishocks(5)=ishock/fsigma(5,5)
   compute bishocks(baseentry)=fsigma*ishocks
   compute fshocks(1)(baseentry)=bishocks(baseentry)(1)
   compute fshocks(2)(baseentry)=bishocks(baseentry)(2)
   compute fshocks(3)(baseentry)=bishocks(baseentry)(3)
   compute fshocks(4)(baseentry)=bishocks(baseentry)(4)
   compute fshocks(5)(baseentry)=bishocks(baseentry)(5)
   forecast(paths,model=tvecm,results=sims)
   # fshocks
   do i=1,5
      set girf(i) = girf(i)+(sims(i)-basesims(i))
   end do i
end do draw
*
do i=1,5
   set girf(i) = girf(i)/ndraws
end do i
*
graph(footer=$
  "GIRF for What to One S.D. Shock in What")
# girf(4)
graph(footer=$
  "GIRF for What to One S.D. Shock in What")
# girf(3)
graph(footer=$
  "GIRF for What to One S.D. Shock in What")
# girf(1)
*

Re: Generalized Impulse Responses

Posted: Mon Jan 16, 2012 1:22 pm
by TomDoan
Please use the "Code" button (select the program lines then hit "Code"). It makes the posts easier to read.

If you track it back, the %PSDFACTOR is applying to TVECMSIGMA which is being generated by SWEEP. The SWEEP is supposed to have the dependent variables on the first line and the explanatory variables on the second. You have half the explanatory variables on the first, and the other half on the second. You need to fix that.

Whatever it does, a RATS 4.1 program for handling VAR's isn't worth the effort at direct modification; there are too many model handling features missing.

Re: Generalized Impulse Responses

Posted: Mon Jan 16, 2012 1:30 pm
by nazif
it is like this, is it wrong

Code: Select all

sweep(group=switch(t))
# LIP{1 to 4} LCPI{1 to 4} INTBRATE{1 to 4} LRERCPI_SA{1 to 4} LCRE{1 to 4}
# constant lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
compute tvecmsigma=%sigma
after fixing the code could you please tell how can i create girfs for all responses to variables
thanks

Re: Generalized Impulse Responses

Posted: Mon Jan 16, 2012 1:42 pm
by nazif
I have changed it with this

Code: Select all

sweep(group=switch(t))
# LIP LCPI INTBRATE LRERCPI_SA LCRE
# constant LIP{1 to 4} LCPI{1 to 4} INTBRATE{1 to 4} LRERCPI_SA{1 to 4} LCRE{1 to 4} lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
but still get the error
## MAT2. Matrices with Dimensions 5 x 5 and 2 x 1 Involved in %PSDFACTOR Operation

Re: Generalized Impulse Responses

Posted: Mon Jan 16, 2012 4:10 pm
by nazif
Dear Doan,
I finally come up with the following model. The code is working without no problem. But there are still some questions stick to my mind .
- First I am not sure whether the calculated girfs are correct or not. Which girfs, girf(1) or girf(2) ..... corresponds to which variable.
- If you look at my data you will see that I am using the levels of the variables in the estimates. That may explain why the produced GIRF's are explosive, but i don't know how to fix this
- Forecasting function is working properly but as I said before I don't know whether the forecasting sample is chosen correctly.
- Furthermore based on this model I have to also calculate nonlinear irfs for the upper and the lower regime. for int>.228 and int<.228 similar to one in the paper of Balke (2000) that I have posted to you. Can I produce the girfs for regime 1 regime 2 by selecting different starting points for forecasting function?
- I have to also produce the responses of each variable under both regimes with their error bands.

I am also attaching my data file in case you need.
Thanks for your help again.

Nazif

Code: Select all

* SMS_5_2.RPF
* Switching Models and Structural Breaks
* Example 5.2
*
* Based upon Balke and Fomby(1997), "Threshold Cointegration,"
* International Economic Review, vol 38, no 3, 627-45.
*
* Data file is a reconstruction.
*
* This estimates the thresholds using the bivariate likelihood, computes
* an eventual forecast function and GIRF.
*
open data montra_2011_4.xls
calendar(m) 1986
data(format=xls,org=columns) 1986:1 2010:11
*
set thresh = INTBRATE{1}
dec frml[int] switch
frml switch = 1+fix(INTBRATE{1}>=0.228)
*
* Estimate the model at the best breaks to get the covariance matrix.
*
sweep(group=switch(t))
# LIP LCPI INTBRATE LRERCPI_SA LCRE
# constant LIP{1 to 4} LCPI{1 to 4} INTBRATE{1 to 4} LRERCPI_SA{1 to 4} LCRE{1 to 4} lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
compute tvecmsigma=%sigma
*

*
compute nvar=5
compute nregime=2
*
system(model=basevecm)
variables LIP LCPI INTBRATE LRERCPI_SA LCRE
lags 1 to 4
det constant lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
end(system)
dec rect[frml] tvecfrml(nvar,nregime)
do i=1,nregime
   estimate(smpl=(switch(t)==i))
   do j=1,nvar
      frml(equation=%modeleqn(basevecm,j)) tvecfrml(j,i)
   end do j
end do i
*
dec vect[frml] switchf(nvar)
do j=1,nvar
   frml switchf(j) %modeldepvars(basevecm)(j) = tvecfrml(j, switch(t))
end do j
* My endogenous variables are LIP LCPI INTBRATE LRERCPI_SA LCRE
group tvecm switchf(1) switchf(2) switchf(3) switchf(4) switchf(5)  

*
* Eventual forecast function, starting with 2003:4 data (Post-inflation targeting period).
*
forecast(model=tvecm,from=2003:4,steps=24,results=eff)
graph(footer=$
   "Eventual Forecast Function for Credit, starting at 2003:4")
# eff(5)
graph(footer=$
   "Eventual Forecast Function for CPI, starting at 2003:4")
# eff(2)
*
* GIRF starting in 1998:3 for a one s.d. shock to DR correlated with FF
* using the estimated covariance matrix. (1969:3 has values for both
* rates which are close to the average for the full period).
*
compute ndraws=5000
compute baseentry=2003:3
compute nsteps   =40
*
dec vect[series] fshocks(5) girf(5)
dec series[vect] bishocks
dec vect ishocks
*
smpl baseentry baseentry+(nsteps-1)
do i=1,5
   set girf(i) = 0.0
end do i
*
compute fsigma=%psdfactor(tvecmsigma,||1,2,3,4,5||)
*
do draw=1,ndraws
   gset bishocks = %ranmvnormal(fsigma)
   set fshocks(1) = bishocks(t)(1)
   set fshocks(2) = bishocks(t)(2)
   set fshocks(3) = bishocks(t)(3)
   set fshocks(4) = bishocks(t)(4)
   set fshocks(5) = bishocks(t)(5)

   forecast(paths,model=tvecm,results=basesims)
   # fshocks
   compute ishock=fsigma(5,5)
   compute ishocks=inv(fsigma)*bishocks(baseentry)
   compute ishocks(5)=ishock/fsigma(5,5)
   compute bishocks(baseentry)=fsigma*ishocks
   compute fshocks(1)(baseentry)=bishocks(baseentry)(1)
   compute fshocks(2)(baseentry)=bishocks(baseentry)(2)
   compute fshocks(3)(baseentry)=bishocks(baseentry)(3)
   compute fshocks(4)(baseentry)=bishocks(baseentry)(4)
   compute fshocks(5)(baseentry)=bishocks(baseentry)(5)
   forecast(paths,model=tvecm,results=sims)
   # fshocks
   do i=1,5
      set girf(i) = girf(i)+(sims(i)-basesims(i))
   end do i
end do draw
*
do i=1,5
   set girf(i) = girf(i)/ndraws
end do i
*
graph(footer=$
  "GIRF for What to One S.D. Shock in What")
# girf(4)
graph(footer=$
  "GIRF for What to One S.D. Shock in What")
# girf(3)
graph(footer=$
  "GIRF for What to One S.D. Shock in What")
# girf(1)
*
table

Re: Generalized Impulse Responses

Posted: Thu Jan 19, 2012 2:50 pm
by TomDoan
nazif wrote:I have changed it with this

Code: Select all

sweep(group=switch(t))
# LIP LCPI INTBRATE LRERCPI_SA LCRE
# constant LIP{1 to 4} LCPI{1 to 4} INTBRATE{1 to 4} LRERCPI_SA{1 to 4} LCRE{1 to 4} lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
but still get the error
## MAT2. Matrices with Dimensions 5 x 5 and 2 x 1 Involved in %PSDFACTOR Operation
This generalizes the factorization to an arbitrary number of variables. In your code, the shuffling vector was ||2,1|| which is specifically for a 2-variable system.

Code: Select all

*
* Do a factorization with the shock of interest (in this case, the
* discount rate) first.
*
compute shockto=2
dec vect[int] shuffle(nvar)
ewise shuffle(i)=%if(i==1,shockto,i-(i<=shockto))
compute fsigma=%psdfactor(tvecmsigma,shuffle)

Re: Generalized Impulse Responses

Posted: Fri Jan 20, 2012 4:14 am
by nazif
Dear Doan,
Sorry for bothering you again. I tried to modify the GIRF code bu the following error is found. As I understand in order to obtain factorization for a specific variable I need to change number in compute shockto=3 command.

If I also understand it correctly there is no difference between the Balke's and my simple TVAR code except that Balke uses bootstrapping simulations. If so can I use VARBootDraw procedure to get irfs based on bootstapped residuals? Which one is more convenient in these models, Bootstrap or Gaussian?

Thanks for your precious help again, you helped me a lot.
Nazif

Code: Select all

## SX22. Expected Type INTEGER, Got REAL Instead
>>>>to,i-(i<=shockto))<<<<

Code: Select all

open data montra_2011_4.xls
calendar(m) 1986
data(format=xls,org=columns) 1986:1 2010:11
*
set thresh = INTBRATE{1}
dec frml[int] switch
frml switch = 1+fix(INTBRATE{1}>=0.228)
*
* Estimate the model at the best breaks to get the covariance matrix.
*
sweep(group=switch(t))
# LIP LCPI INTBRATE LRERCPI_SA LCRE
# constant LIP{1 to 4} LCPI{1 to 4} INTBRATE{1 to 4} LRERCPI_SA{1 to 4} LCRE{1 to 4} lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
compute tvecmsigma=%sigma
*

*
compute nvar=5
compute nregime=2
*
system(model=basevecm)
variables LIP LCPI INTBRATE LRERCPI_SA LCRE
lags 1 to 4
det constant lpetpri{1 to 4} ffr{1 to 4} indus{1 to 4}
end(system)
dec rect[frml] tvecfrml(nvar,nregime)
do i=1,nregime
   estimate(smpl=(switch(t)==i))
   do j=1,nvar
      frml(equation=%modeleqn(basevecm,j)) tvecfrml(j,i)
   end do j
end do i
*
dec vect[frml] switchf(nvar)
do j=1,nvar
   frml switchf(j) %modeldepvars(basevecm)(j) = tvecfrml(j, switch(t))
end do j
* My endogenous variables are LIP LCPI INTBRATE LRERCPI_SA LCRE
group tvecm switchf(1) switchf(2) switchf(3) switchf(4) switchf(5)

*
* GIRF starting in 2003:1 for a one s.d. shock to DR correlated with FF
*
compute ndraws=5000
compute baseentry=1988:01
compute nsteps   =40
*
dec vect[series] fshocks(5) girf(5)
dec series[vect] bishocks
dec vect ishocks
*
smpl baseentry baseentry+(nsteps-1)
do i=1,5
   set girf(i) = 0.0
end do i
*
*
* Do a factorization with the shock of interest first.
*
compute shockto=3
dec vect[int] shuffle(nvar)
ewise shuffle(i)=%if(i==1,shockto,i-(i<=shockto))
compute fsigma=%psdfactor(tvecmsigma,shuffle)
*
do draw=1,ndraws
   gset bishocks = %ranmvnormal(fsigma)
   set fshocks(1) = bishocks(t)(1)
   set fshocks(2) = bishocks(t)(2)
   set fshocks(3) = bishocks(t)(3)
   set fshocks(4) = bishocks(t)(4)
   set fshocks(5) = bishocks(t)(5)

   forecast(paths,model=tvecm,results=basesims)
   # fshocks
   compute ishock=fsigma(5,5)
   compute ishocks=inv(fsigma)*bishocks(baseentry)
   compute ishocks(5)=ishock/fsigma(5,5)
   compute bishocks(baseentry)=fsigma*ishocks
   compute fshocks(1)(baseentry)=bishocks(baseentry)(1)
   compute fshocks(2)(baseentry)=bishocks(baseentry)(2)
   compute fshocks(3)(baseentry)=bishocks(baseentry)(3)
   compute fshocks(4)(baseentry)=bishocks(baseentry)(4)
   compute fshocks(5)(baseentry)=bishocks(baseentry)(5)
   forecast(paths,model=tvecm,results=sims)
   # fshocks
   do i=1,5
      set girf(i) = girf(i)+(sims(i)-basesims(i))
   end do i
end do draw
*
do i=1,5
   set girf(i) = girf(i)/ndraws
end do i
*
graph(footer=$
  "GIRF for LCRE to One S.D. Shock in Intbrate")
# girf(5)
graph(footer=$
  "GIRF for LRER to One S.D. Shock in Intbrate")
# girf(4)
graph(footer=$
  "GIRF for  to Intbrate S.D. Shock in in Intbrate")
# girf(3)
graph(footer=$
  "GIRF for LCPI to One S.D. Shock in in Interest Rate")
# girf(2)
graph(footer=$
  "GIRF for LIP to One S.D. Shock in in Interest Rate")
# girf(1)
*