Page 1 of 2

Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Fri Mar 13, 2015 9:23 am
by jfwarren
Hi,

I'm fairly new to RATS and hope you can help.

I'm running a two variable VAR for US Real GDP and the US savings rate and imposing a long run restriction (Blanchard-Quah restriction) that states that shocks to the savings rate have no long run effect on the growth rate of GDP.
I'm using the 2nd difference of the Log of Real GDP and the 1st difference of the savings rate and so expect to see that the accumulated impulse response of output to the savings shock converges to zero.

I get this result when I run the simple Impulse Responses but I also want to get the confidence bands for these too. Following the MonteCarlo procedure, I get very different impulse responses. Can you help? I'm not sure what is wrong with my code or whether there is a calibration discrepancy between the two.

Code: Select all

*
OPEN DATA "C:\Users\jfw43\Dissertation\Eviews and Data Files\Savings Rate and Log GDP in Differences.RAT"
DATA(FORMAT=RATS) 1959:01 2014:03 D2LRGDP DSRATE
*
system(model=svar)
var d2lrgdp dsrate
lags 1 
det constant 
end(system)
*
estimate(noprint,resids=resids)
*
compute factor=%bqfactor(%sigma,%varlagsums)
*
declare rectangular[series]  impulses(2,2)
com implabels = ||'Output','Savings Rate'||
impulse(decomp=factor,result=impulses,model=svar) * 40 *
*
@varirf(model=svar,decomp=factor,steps=40,page=byshocks,$
	variables=||"Real GDP","Savings Rate"||,shocks=||"Output", "Savings"||,accum=||1,2||)

And this for MC simulations:

Code: Select all

****MONTE CARLO ESTIMATION******
*
OPEN DATA "C:\Users\jfw43\Dissertation\Eviews and Data Files\Savings Rate and Log GDP in Differences.RAT"
DATA(FORMAT=RATS) 1959:01 2014:03 D2LRGDP DSRATE
*
compute [vect[strings]] shocklabels=||"Output","Savings"||
compute [vect[strings]] varlabels=||"Real GDP","Savings Rate"||
*
system(model=svar)
var d2lrgdp dsrate
lags 1 
det constant 
end(system)
*
estimate(noprint,resids=resids)
@BQDoDraws(model=varmodel)
@MCGraphIRF(model=varmodel,shocklabels=shocklabels,varlabels=varlabels)

Many thanks

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Fri Mar 13, 2015 8:22 pm
by TomDoan
You left the ACCUM=||1,2|| option off the @BQDODRAWS.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Sat Mar 14, 2015 7:42 am
by jfwarren
Thank you for a speedy reply.

I added in the accumulate option and I still get a very different looking impulse response function (i.e. the main thing is that the Monte Carlo ones are very smooth and do not give me a convergence to zero on the GDP response to a savings shock). Why might this be?

Are doing the Monte Carlo draws the best method to getting the standard errors? I'd prefer to plot my graphs manually in Excel, can I extract the standard errors in another format.

Many thanks,

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Sat Mar 14, 2015 10:34 am
by TomDoan
jfwarren wrote:Thank you for a speedy reply.

I added in the accumulate option and I still get a very different looking impulse response function (i.e. the main thing is that the Monte Carlo ones are very smooth and do not give me a convergence to zero on the GDP response to a savings shock). Why might this be?
They will be smoother because they're the average (or median) across a set of draws. Convergence to zero will likely be slower, sometimes much slower. See what happens if you increase the number of steps (perhaps to 100).
jfwarren wrote: Are doing the Monte Carlo draws the best method to getting the standard errors?
Yes.
jfwarren wrote: I'd prefer to plot my graphs manually in Excel, can I extract the standard errors in another format.
Use @MCPROCESSIRF. You could then copy the information out to an Excel file using COPY.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Sun Mar 15, 2015 11:43 am
by jfwarren
Hi Tom,

Thank you so much for your help. I increased the number of steps and it now converges to zero and looks very like the impulse responses I obtained from my original code.

I am trying to implement the @MCProcessIRF code to graph my own impulse response functions in Excel.

This is my code:

Code: Select all

compute nvar = 2
compute nlags = 1
compute nsteps = 50
compute ndraws = 5000
*
system(model=svar)
var d2lrgdp dsrate
lags 1 to nlags
det 
end(system)
estimate(noprint)
*
declare vect[rect] %%responses
dim %%responses(ndraws)
*
infobox(action=define, progress, lower=1, upper=ndraws) "Monte Carlo Integration"
do draw=1, ndraws
compute factor=%bqfactor(%sigma,%varlagsums)
impulse(noprint,model=svar,factor=factor,results=impulses,steps=nsteps)
*
do i=1, %rows(accum)
      do j=1,nvar
         acc impulses(accum(i),j) 1 steps
      end do j
   end do i
*
dim %%responses(ndraws)(nvar*nvar,nsteps)
ewise %%responses(ndraws)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
infobox (current=draw)
end do draw
infobox(action=remove)
*
@MCProcessIRF(model=svar,lower=lower,upper=upper,irf=irf)

For "@MCProcessIRF(model=svar,lower=lower,upper=upper,irf=irf)" I used the program file in https://estima.com/forum/viewtopic.php?f=8&t=1118 "b_l_jme2009.rpf" as a template.
A)What does lower=lower, upper=upper, irf=irf refer to?

B) When I run this output I get an error on the accumulate do loop. Why might this be? I want to accumulate both impulses.

Many thanks,
J

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Sun Mar 15, 2015 8:28 pm
by TomDoan
For (B) just use your original program and replace the @MCGRAPHIRF with @MCPROCESSIRF.

For (A) lower=lower, upper=upper, irf=irf, that's described in the help for the procedure:

* These are the outputs. They all need to be used. Each generates a
* RECT[SERIES], where x(i,j) is the series of responses of variable i to
* shock j.
*
* IRF=RECT[SERIES] with the central measure of the impulse responses
* LOWER=RECT[SERIES] with the lower bounds
* UPPER=RECT[SERIES] with the upper bounds

If you want to copy the information to Excel, you would do the @MCPROCESSIRF, then do something like

copy(format=xls,org=columns) / irf lower upper

For each combination of variable i and shock j, you have an IRF, a LOWER and an UPPER series.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Mon Mar 16, 2015 4:26 am
by jfwarren
Thank you Tom! That worked a treat.

My query is that the impulse responses although qualitatively the same as the simple accumulated IRs (I put them into excel and took the cumulative sum myself) I got from my original estimation the numbers are a bit different... why might this be? Is there an error somewhere in the calibration of my results from the MC simulation.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Mon Mar 16, 2015 7:58 am
by TomDoan
If you're talking about the IRF's, the output from @MCPROCESSIRF is (by default) the mean of the cloud of responses. That won't be the same as the response at the least squares estimates.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Wed Mar 18, 2015 6:10 am
by jfwarren
Thank you, that makes sense.

I am trying to estimate a five variable VAR to analyse the effects of a savings shock on GDP growth as well as the nominal interest rate, consumption and inflation. This is similar to that in Gali "Technology, Employment and the Business Cycle" (1999). It doesn't matter what the additional restrictions are as these are just to identify the the system and as long as they don't restrict the effect of a savings shock I believe it won't affect the impulse responses to this shock? Is this right?

The ordering of my variables is {second difference Log Real GDP, first difference savings rate, CPI inflation, first difference nominal interest rate, first difference log consumption}

Code: Select all

dec rect lr(5,5) sr(5,5)
input lr
. 0 . . .
. . . . .
. . . . .
. . . . .
. . . . .
input sr
. . 0 0 0
. . 0 0 0
. . . 0 0
. . . . 0
. . . . .
This puts no contemporaneous restrictions on the effects of output and savings rate to their own and each other's shocks and then implements the same LR restriction as in my bivariate model.

My IRF results for a savings shock are attached - I'm surprised that there is no response after one period for all of the variables??

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Wed Mar 18, 2015 7:53 am
by TomDoan
jfwarren wrote:Thank you, that makes sense.

I am trying to estimate a five variable VAR to analyse the effects of a savings shock on GDP growth as well as the nominal interest rate, consumption and inflation. This is similar to that in Gali "Technology, Employment and the Business Cycle" (1999). It doesn't matter what the additional restrictions are as these are just to identify the the system and as long as they don't restrict the effect of a savings shock I believe it won't affect the impulse responses to this shock? Is this right?
Not necessarily. "B" models generally depend upon the full set of restrictions.
jfwarren wrote: The ordering of my variables is {second difference Log Real GDP, first difference savings rate, CPI inflation, first difference nominal interest rate, first difference log consumption}

Code: Select all

dec rect lr(5,5) sr(5,5)
input lr
. 0 . . .
. . . . .
. . . . .
. . . . .
. . . . .
input sr
. . 0 0 0
. . 0 0 0
. . . 0 0
. . . . 0
. . . . .
This puts no contemporaneous restrictions on the effects of output and savings rate to their own and each other's shocks and then implements the same LR restriction as in my bivariate model.

My IRF results for a savings shock are attached - I'm surprised that there is no response after one period for all of the variables??
That sounds like you have lags=0 in the VAR.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Wed Mar 18, 2015 9:32 am
by jfwarren
Thank you - the zero lags was my problem. It looks much better now.

I'm trying to run the Monte Carlo simulations for this program as well following b_l_jme_2009.prg from Bjornland and Leitemo's paper (2009).

It runs fine until this point:

Code: Select all

	dim %%responses(draw)(nvar*nvar,nsteps)
	ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
	infobox (current=draw)
end do draw
infobox(action=remove)
where I get the error

Code: Select all

## SX22. Expected Type STRING, Got INTEGER Instead
>>>>box (current=draw)<<<<
I didn't seem to have this problem before in my previous MC program. What does the error mean and how do I fix it? I'll attach the program file.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Wed Mar 18, 2015 9:51 am
by TomDoan
You have a space between infobox and the ( for the option field.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Wed Mar 18, 2015 10:58 am
by jfwarren
Thanks! I think I must be getting quite tired missing these things..!!

I've got a working MC code now but despite increasing the number of steps and draws, can't seem to get the response of output to a savings shock to converge to zero as it should do by my long run restriction.
Is there something wrong with my code or is this perhaps a side effect of imposing short run restrictions as well as the LR restriction.

Code: Select all

*
compute nvar = 5
compute nlags = 1
compute nsteps = 200
compute ndraws = 1000
*
compute [vect[strings]] shocklabels=||"Output","Savings","Inflation","Interest Rate","Consumption"||
compute [vect[strings]] varlabels=||"Real GDP","Savings Rate","Inflation","Nominal Interest Rate","Consumption"||
*
system(model=fivevar)
var d2lrgdp ds dinf dr dlcons
lags 1 to nlags
det
end(system)
estimate(noprint,resids=resids)
compute vsigma=%sigma
*
dec rect lr(5,5) sr(5,5)
input lr
. 0 . . .
. . . . .
. . . . .
. . . . .
. . . . .
input sr
. . 0 0 0
. . 0 0 0
. . . 0 0
. . . . 0
. . . . .
dec vect[strings] shocklabels varlabels
compute shocklabels=||"Output","Savings","Inflation","Interest rate","Consumption"||
compute varlabels=||"Real GDP","Savings Rate","CPI Inflation","Nominal Interest rate","Consumption"||
*
@ShortAndLong(lr=lr,sr=sr,masum=inv(%varlagsums)) %sigma f
compute fd=%xdiag(f)
ewise f(i,j)=f(i,j)/fd(j)
*
@varirf(noprint,model=fivevar,steps=nsteps,factor=f,page=byshock,accum=||1,2,4,5||,$
  shocks=shocklabels,varlabels=varlabels)
*
procedure SRLRDoDraws
*
option model     model
option integer   ndraws   1000
option integer   nsteps   200
option vect[int] accum   ||1,2,4,5||
option rect      lr
option rect      sr
*
local integer nvar
local rect    fxx fwish fsigmad factor
local integer wishdof
local rect    betaols betau betadraw
local vect    ix
local symm    sigmad
local integer i j draw
*
if .not.%defined(fivevar) {
   disp "###SRLRDoDraws(MODEL=fivevar,other options)"
   return
}
compute nvar=%modelsize(fivevar)
*
compute fxx    =%decomp(%xx)
compute fwish  =%decomp(inv(%nobs*%sigma))
compute wishdof=%nobs-%nreg
compute betaols=%modelgetcoeffs(fivevar)
*
*
local rect[series] impulses(nvar,nvar)
declare vect[rect]   %%responses(ndraws)
*
infobox(action=define, progress, lower=1, upper=ndraws) "Monte Carlo Integration"
do draw=1, ndraws
	if %clock(draw,2)==1 {
      compute sigmad  =%ranwisharti(fwish,wishdof)
      compute fsigmad =%decomp(sigmad)
      compute betau   =%ranmvkron(fsigmad,fxx)
      compute betadraw=betaols+betau
   }
   else
      compute betadraw=betaols-betau
   compute %modelsetcoeffs(model,betadraw)
*
@ShortAndLong(lr=lr,sr=sr,masum=inv(%modellagsums(fivevar))) sigmad factor
impulse(noprint,model=fivevar,results=impulses,steps=nsteps)
	*
	do i=1, %rows(accum)
    	do j=1,nvar
        acc impulses(accum(i),j) 1 nsteps
    	end do j
	end do i
	*
	dim %%responses(draw)(nvar*nvar,nsteps)
	ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
	infobox(current=draw)
end do draw
infobox(action=remove)
*
compte %modelsetcoeffs(model,betaols)
*
end SRLRDoDraws
*
@SRLRDoDraws(accum=||1,2,3,4,5||,model=fivevar,lr=lr,sr=sr)
*@MCProcessIRF(model=fivevar,lower=lower,upper=upper,irf=irf)
@MCGraphIRF(model=fivevar,shocklabels=shocklabels,varlabels=varlabels,page=byshock)


Thank you

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Wed Mar 18, 2015 12:20 pm
by TomDoan
Don't change anything with the SRLRDODRAWS procedure---take it exactly as it is in the Bjornland-Leitemo replication. Instead of using the options to input your information (which is the whole point of procedures), you tried to edit the procedure to fit your model and ended up using an incorrect combination of OLS and sampled coefficients.

Re: Discrepancy between Simple IRFs and Monte Carlo IRFs

Posted: Thu Mar 19, 2015 6:41 am
by jfwarren
Thank you - got that sorted. I am totally new to this sort of software, have only ever used pre-set function windows in Eviews.

I am using the

Code: Select all

@MCGraphIRF(model=threevar,shocklabels=shocklabels,varlabels=varlabels,page=byshock)
@MCProcessIRF(model=threevar,percentiles=||.16,.84||,center=median,lower=lower,upper=upper,irf=irf)
copy(format=xls,org=columns) / irf lower upper
after the @MCProcessIRF function.

However, when I ran it the first time I got an option to save the output.... but I've used the same command today and it doesn't let me have that option and just finishes the MC integration a short progress box flashes up for a second and then there is neither any output or an option to save the output in my file?