IRF minimum distance estimator

Questions and discussions on Vector Autoregressions
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

IRF minimum distance estimator

Unread post by chaveslima »

I would like to calculate the Minimum Distance Estimation between empirical and theoretical impulse response functions based on Huelsewig, Mayer and Wollmershaeuser (2005). I appreciate anyone sending me some tips on how to do this on RATS.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: IRF minimum distance estimator

Unread post by TomDoan »

This shows the general structure of the calculation. Without the data, you obviously can't fully demonstrate it, but this shows how to set up and get the IRF's for the theoretical model.

Code: Select all

*
* (First run at) Replication file for Hulsewig, Mayer &
* Wollmershauser(2006),  "Bank loan supply and monetary policy
* transmission in Germany: An assessment based on matching impulse
* responses," Journal of Banking & Finance, vol. 30, no 10, 2893-2910.
*
declare real b1 b2 nai delta1 delta2 gamma1 gamma2 gamma3
declare series y l rl rm eta
*
* Set up the DSGE. This uses the original optimization equation from the
* appendix rather than the partially substituted one in the main text.
*
frml(identity) eqna6 = beta*l{-1}-(1+beta)*l+l{1}+nai*(rl-rm)
frml(identity) eqn14 = b2*rl - (b1*y - l)
frml(identity) eqn15 = y - (gamma1*y{1}+gamma2*rl{1}+gamma3*rl{2})
frml(identity) eqn16 = rm - (delta1*rm{1}+delta2*rm{2}+eta)
frml s1 = eta
*
compute nsteps=20
*
compute beta=.99
compute b1=2.1887,b2=.0142,nai=.0010,delta1=1.4665,delta2=-.5204
compute gamma1=.9985,gamma2=.0009,gamma3=-.0026
*
group loanmodel eqna6 eqn14 eqn15 eqn16 s1
*
dsge(a=a,f=f,model=loanmodel) y rm l rl eta
*
* They don't report the standard error of the shock, but it appears to
* be roughly .2.
*
@dlmirf(a=a,f=f*.2,steps=nsteps,varlabels=||"GDP","RM","LOAN","RL"||,page=byshock)
*
* You need the estimated IRF's from the VAR and their variances in order
* to do the optimization. This assumes that the estimated IRF's to the
* rate shock are in the series estimated(i,1) and the corresponding
* variances are in estvar(i,1).
*
nonlin(parmset=dsgeparms) b1 b2 nai delta1 delta2 gamma1 gamma2 gamma3
declare real ceemetric
find(parmset=dsgeparms) minimum ceemetric
   *
   * Solve the DSGE given the current values
   *
   dsge(a=a,f=f,model=loanmodel) y rm l rl eta
   @dlmirf(a=a,f=f*.2,steps=nsteps,results=theoretical)
   compute ceemetric=0.0
   do h=1,nsteps
      do i=1,4
         compute ceemetric=ceemetric+(theoretical(i,1)(h)-estimated(i,1)(h))^2/estvar(i,1)(h)
      end do i
   end do h
end find
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Dear Sr.

I am trying to replicate the paper "Minimum Distance Estimation between empirical and theoretical impulse response
functions based on Huelsewig, Mayer and Wollmershaeuser (2005)". You've already sent me part of the procedure,
but I still need the VAR program and database to run. In the procedure I've got from you it says:
.....
* You need the estimated IRF's from the VAR and their variances in order
* to do the optimization. This assumes that the estimated IRF's to the
* rate shock are in the series estimated(i,1) and the corresponding
* variances are in estvar(i,1).[/i][/i]
....

So, I would appreciate you sending me this part of the program.

thanks

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

Re: IRF minimum distance estimator

Unread post by TomDoan »

If you get the data from the authors, I could show you how to do that.
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Tomm

I have similar data from Brazil. If you send me the whole program I can plug in
my data and run it. Would it be easier for you if I send you my data? How can I attach an
excel file to this message?
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Dear Tom

If you tell me how to produce the estimated IRF's to the rate shock [estimated(i,1)] and its corresponding
corresponding variances [estvar(i,1)] in the VAR model, I could plug in the program you've sent me.

regards

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

Re: IRF minimum distance estimator

Unread post by TomDoan »

chaveslima wrote:Dear Tom

If you tell me how to produce the estimated IRF's to the rate shock [estimated(i,1)] and its corresponding
corresponding variances [estvar(i,1)] in the VAR model, I could plug in the program you've sent me.

regards

Ricardo
Those are just the standard Monte Carlo IRF means and variances.
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Tom, I am running this model, but a couple of bugs have come up
open data credsin3.xls
calendar(q) 1995:1
data(format=xls,org=columns) 1995:1 2012:1 pibr dpib selic cred
x11(multiplicative,adjusted=apibr) pibr
x11(multiplicative,adjusted=adpib) dpib
x11(multiplicative,adjusted=acred) cred
set lpibr = log(apibr)
set lcred = log(acred)
*
*print / lpibr dpib selic lcred
*
system(model=varmodel)
variables lpibr adpib selic lcred
lags 1 to 1
end(system)
*
*compute [vect[strings]] implabel=||"lpibr","adpib","selic","lcred"||
*
estimate(noprint)
@MCVARDoDraws(model=varmodel,DRAWS=1000)
@MCGraphIRF(model=varmodel)
impulse(model=varmodel,noprint,result=estimated,steps=24,cv=%sigma)
*
do i = 1,4
print / estimated(i,1)
end do
*
*******************
* (First run at) Replication file for Hulsewig, Mayer &
* Wollmershauser(2006),  "Bank loan supply and monetary policy
* transmission in Germany: An assessment based on matching impulse
* responses," Journal of Banking & Finance, vol. 30, no 10, 2893-2910.
*
declare real beta b1 b2 nai delta1 delta2 gamma1 gamma2 gamma3
declare series y l rl rm eta
*
* Set up the DSGE. This uses the original optimization equation from the
* appendix rather than the partially substituted one in the main text.
*
frml(identity) eqna6 = beta*l{-1}-(1+beta)*l+l{1}+nai*(rl-rm)
frml(identity) eqn14 = b2*rl - (b1*y - l)
frml(identity) eqn15 = y - (gamma1*y{1}+gamma2*rl{1}+gamma3*rl{2})
frml(identity) eqn16 = rm - (delta1*rm{1}+delta2*rm{2}+eta)
frml s1 = eta
*
compute nsteps=20
*
compute beta=.99
compute b1=2.1887,b2=.0142,nai=.0010,delta1=1.4665,delta2=-.5204
compute gamma1=.9985,gamma2=.0009,gamma3=-.0026
*
group loanmodel eqna6 eqn14 eqn15 eqn16 s1
*
dsge(a=a,f=f,model=loanmodel) y rm l rl eta
*
* They don't report the standard error of the shock, but it appears to
* be roughly .2.
*
@dlmirf(a=a,f=f*.2,steps=nsteps,varlabels=||"GDP","RM","LOAN","RL"||,page=byshock,results=theoretical)
*

* You need the estimated IRF's from the VAR and their variances in order
* to do the optimization. This assumes that the estimated IRF's to the
* rate shock are in the series estimated(i,1) and the corresponding
* variances are in estvar(i,1).
*
nonlin(parmset=dsgeparms) b1 b2 nai delta1 delta2 gamma1 gamma2 gamma3
declare real ceemetric
after this point it stops working
find minimum ceemetric
dsge(a=a,f=f,model=loanmodel) y rm l rl eta
   @dlmirf(a=a,f=f*.2,steps=nsteps,results=theoretical)
   compute ceemetric=0.0
   do h=1,nsteps
      do i=1,4
         compute ceemetric=ceemetric+(theoretical(i,1)(h)-estimated(i,1)(h))^2/%sigma(i,1)(h)
      end do i
   end do h
end find
question: can I use %sigma(i,1) to represent IRF variance?
you can see that I am mixing my data with Huelsewigs theoretical IRF. It is
just to run the model. Once I run it and produce the CEEMETRIC statistics, I will
redo my model using correct theoretical IRF. Thanks a lot for any help
moderator
Site Admin
Posts: 269
Joined: Thu Oct 19, 2006 4:33 pm

Re: IRF minimum distance estimator

Unread post by moderator »

Ricardo,

Looking at the code, I assume this command

> compute ceemetric=ceemetric+(theoretical(i,1)(h)-estimated(i,1)(h))^2/%sigma(i,1)(h)

is giving you an error like this

## SX17. Missing Operator or Adjacent Operands
>>>>(h))^2/%sigma(i,1)(<<<<

The %SIGMA array is just a regular two-dimensional symmetric array, so the reference to element (h) after the (i,1) reference doesn't make any sense. In Tom Doan's original code, the (h) reference a given step (horizon) for the IRF and variances. I'm not sure what you had in mind there, but if you just wanted to refer the fixed (i.e. unchanging over the IRF horizon) variances stored in %sigma, you could do

compute ceemetric=ceemetric+(theoretical(i,1)(h)-estimated(i,1)(h))^2/%sigma(i,1)

I'm not sure that really makes sense though?

Regards,
Tom Maycock
Estima
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Hello Tom

My minimum distance estimator model is working, but I would be very thankful you helping me with a couple of things:
1) The model sets up the parameters (b1=2.1887, b2=0.0142, nai=0.0010, and so on) to do a DSGE and calculate the minimum distance estimator. In the Huelsewig paper, however, the same parameters values are found as a product of the minimum distance estimator calculation. Why set up b1, b2, etc. using those velue?;
2) When I finish running my model, after the last line on the program bellow, it gives me the following message:

FIND Optimization - Estimation by Simplex
Function Value 93.0423
NO ESTIMATED COEFFICIENTS
Variable Coeff
**********************************************

How can I get the variables coefficients? Are those coefficients on the PARMSET=DGSEPARMS option of the nonlin?

----------------------------------------------------------------------------

open data credsin3.xls
calendar(q) 1995:1
data(format=xls,org=columns) 1995:1 2012:1 pibr dpib selic cred
x11(multiplicative,adjusted=apibr) pibr
x11(multiplicative,adjusted=adpib) dpib
x11(multiplicative,adjusted=acred) cred
set lpibr = log(apibr)
set lcred = log(acred)
*
*print / lpibr dpib selic lcred
*
system(model=varmodel)
variables lpibr adpib selic lcred
lags 1 to 1
end(system)
*
*compute [vect[strings]] implabel=||"lpibr","adpib","selic","lcred"||
*
estimate(noprint)
@MCVARDoDraws(model=varmodel,DRAWS=1000,step=24)
@MCprocessIRF(model=varmodel,center=mean,stddev=1,IRF=results,upper=ub,lower=lb)
*
do i=1,4
print / lb(i,1) results(i,1) ub(i,1)
end i
*
dec rect[series] sd(4,4)
do i=1,4
do j=1,4
set sd(i,j) = ub(i,j) - results(i,j)
end do j
end do i
do h=1,4
print / sd(h,1)
end do h
*
spgraph(vfields=2,hfields=2,header="estimated irfs")
do i=1,4
graph(key=upleft) 3
# results(i,1)
# ub(i,1) / 2
# lb(i,1) / 2
end do i
spgraph(done)
*
@MCGraphIRF(model=varmodel)
impulse(model=varmodel,noprint,result=estimated,steps=24,cv=%sigma)
*
do i = 1,4
print / estimated(i,1)
end do

*
*******************
* (First run at) Replication file for Hulsewig, Mayer &
* Wollmershauser(2006), "Bank loan supply and monetary policy
* transmission in Germany: An assessment based on matching impulse
* responses," Journal of Banking & Finance, vol. 30, no 10, 2893-2910.
*
declare real beta b1 b2 nai delta1 delta2 gamma1 gamma2 gamma3
declare series y l rl rm eta
*
* Set up the DSGE. This uses the original optimization equation from the
* appendix rather than the partially substituted one in the main text.
*
frml(identity) eqna6 = beta*l{-1}-(1+beta)*l+l{1}+nai*(rl-rm)
frml(identity) eqn14 = b2*rl - (b1*y - l)
frml(identity) eqn15 = y - (gamma1*y{1}+gamma2*rl{1}+gamma3*rl{2})
frml(identity) eqn16 = rm - (delta1*rm{1}+delta2*rm{2}+eta)
frml s1 = eta
*
compute nsteps=24
*
compute beta=.99
compute b1=2.1887,b2=.0142,nai=.0010,delta1=1.4665,delta2=-.5204
compute gamma1=.9985,gamma2=.0009,gamma3=-.0026
*
group loanmodel eqna6 eqn14 eqn15 eqn16 s1
*
dsge(a=a,f=f,model=loanmodel) y rm l rl eta
*
* They don't report the standard error of the shock, but it appears to
* be roughly .2.
*
@dlmirf(a=a,f=f*.2,steps=24,varlabels=||"GDP","RM","LOAN","RL"||,page=byshock,results=theoretical)
*
do j = 1,4
print / theoretical(j,1) results(j,1)
end do
*
spgraph(vfields=2,hfields=3,header="theoretical irfs")
do i=1,4
graph 4
# theoretical(i,1)
# results(i,1)
# ub(i,1) / 3
# lb(i,1) / 3
end do i
spgraph(done)
*************************
*
* You need the estimated IRF's from the VAR and their variances in order
* to do the optimization. This assumes that the estimated IRF's to the
* rate shock are in the series estimated(i,1) and the corresponding
* variances are in estvar(i,1).
*
nonlin(parmset=dsgeparms) b1 b2 nai delta1 delta2 gamma1 gamma2 gamma3
declare real ceemetric
find minimum ceemetric
dsge(a=a,f=f,model=loanmodel) y rm l rl eta
@dlmirf(a=a,f=f*.2,steps=nsteps,results=theoretical)
compute ceemetric=0.0
do h=1,nsteps
do i=1,4
compute ceemetric=ceemetric+(theoretical(i,1)(h)-results(i,1)(h))^2/sd(i,1)(h)
end do i
end do h
end find
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: IRF minimum distance estimator

Unread post by TomDoan »

Although you can back the variances of the responses out of the upper bounds and mean, I've added a VAR option to @MCPROCESSIRF to get those directly. What you want is

@MCprocessIRF(model=varmodel,center=mean,irf=estimated,var=estvar)

The FIND needs the PARMSET

find(parmset=dsgeparms) minimum ceemetric
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Tom

When I do
find(parmset=dsgeparms) minimum ceemetric
it starts printing the last set of graphs indefinitely. That is, it prints the same graph (last graph) all over again.
Any idea of what is happening?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: IRF minimum distance estimator

Unread post by TomDoan »

You need a NOGRAPH on the DLMIRF procedure call. Please note that I didn't have any data to actually run this so there will be some minor glitches.
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Thanks Tom, It did work.
chaveslima
Posts: 18
Joined: Mon Jun 25, 2012 3:49 pm

Re: IRF minimum distance estimator

Unread post by chaveslima »

Hello Tom

My estimation worked all right using find(parmset=dsgeparms), and I am getting the value function and
variables coefficients. A final question is: how can I get the coefficient estimate standard errors?

regards

Ricardo
Post Reply