Page 1 of 1

Fabiani-Mestre 2004 Replication

Posted: Fri Oct 02, 2009 4:35 pm
by TomDoan
The attached zip has a replication for Fabiani & Mestre(2004), "A system approach for measuring the euro area NAIRU," Empirical Economics, vol. 29, no. 2, pp 311-341. This is a fairly complicated three variable state space model with mixed stationary and non-stationary states.

The "baseline" program is more complicated than it needs to be because it includes code to reproduce the results in the paper. Those turn out to find a local mode, rather than the global one. In the paper, the authors also use what amounts to being a diffuse prior on all states, even though some are stationary. This turns out to have a surprisingly long-legged effect on the filtered states.

The state matrices are fairly large and I don't attempt to describe them in the comments. If you want to follow this, you'll almost certainly need to be looking at the paper while you're reading the program.

See Laubach & Williams(2003) for a similar example.
FabianiMestre2004.zip
(118.06 KiB) Downloaded 1573 times

question on Fabiani & Mestre(2004)

Posted: Tue Jun 26, 2012 12:03 pm
by hardmann
Dear Tom:

Fabiani & Mestre(2004), "A system approach for measuring the euro area NAIRU," . This is a fairly complicated three variable state space model with mixed stationary and non-stationary states. I had read their paper and its rats codes. I had encountered a couple of question in baseline model.
1.What are mutiple observable, yf? y,u,ddp? If so, why does not use it directly, y=||y,u,ddp||? Why do use such frml and equation,

Code: Select all

equation yeqn *
# y u ddp
equation zeqn *
# ddp{1 to nlags} ddm{0 to nlags} constant
dec frml[vector] yf
frml yf = %eqnxvector(yeqn,t)-w*%eqnxvector(zeqn,t)
2. In standard measurement and transition equation of RATS, there are A,F,C' metrics, What is W? If %eqnxvector(zeqn,t) are exogenous variables.
However, measurement does not exist exogenous variables, there is Z ,exogenous variables, in transition equation,

3. There are six different DLM commands. Could you give more in detail.



Best regard
hardmann

Re: question on Fabiani & Mestre(2004)

Posted: Tue Jun 26, 2012 1:21 pm
by TomDoan
The model has a mean for the inflation equation that depends upon exogenous variables. The W matrix are the coefficients on those. It's a 3 x 8 matrix where only the bottom row (corresponding to inflation) has values. This was written before we added the MU option to DLM so the only way to get that type of model was to subtract the mean off from the dependent variable(s). With the MU option, you could now just use the natural dependent variables and have a MU option which gives the W x Z.

There are comments describing why each of the DLM instructions are present. The first set has the handling of initial conditions as in the paper; the second has the technically correct method. Each requires initially pegging one of the parameters to prevent convergence to the wrong mode. That's specific to this model and this data set.

Re: Fabiani-Mestre 2004 Replication

Posted: Sat Jun 30, 2012 3:37 am
by hardmann
Dear Tom:

Under your recommand, I directly use f and mu option in DLM.
I modify frml yf = || y,u,ddp|| and add
dec frml[vector] z
frml z = || ddp{1}, ddp{2}, ddp{3}, ddm, ddm{1},ddm{2},ddm{3},constant||
dec frml[vector] m2
frml m2 = w * z

and then add option mu=m2 in six DLM commands

All codes of baseline model is as follows, it is right? :

Code: Select all

*
* Replication for Fabiani & Mestre(2004), "A system approach for
* measuring the euro area NAIRU," Empirical Economics, vol. 29, no. 2,
* pages 311-341
*
* Baseline model
* For numerical reasons, this estimates the variances in log form and
* scales up the constant in the inflation equation by a factor of 1000.
*
calendar(q) 1970
allocate 2000:4
*
* options
*
compute [real] infinity=1e4             ;*** initial loose conditions
compute [integer] nstates=8             ;*** number of states
compute [integer] exclude=nstates       ;*** number of initial obs to drop
compute [integer] nlags=3               ;*** number of lags in measurement equ
*
* Note that you don't *need* to condition on a value as high as
* "nstates" (the exclude option above). With three observables, it takes
* only three data points to resolve the initial 8 diffuse state values.
*
* read data
*
open data awm110500.rat
data(format=rats) / pcd yed mtd compr urx yer

log pcd   / lpcd
log yed   / lyed
log mtd   / lmtd
log compr / lcompr
log yer   / lyer

diff lpcd / dlpcd
diff lyed / dlyed
diff lmtd / dlmtd
diff lcompr / dlcompr
diff lyer / dlyer

diff dlpcd / ddlpcd
diff dlyed / ddlyed
diff dlcompr / ddlcompr
diff dlmtd / ddlmtd

*** data
set ddp = ddlpcd
set ddm = ddlmtd
set y = lyer
set u = urx

*
* Observables from measurement equation(s)
*
equation yeqn *
# y u ddp
*
* Co-states from measurement equation(s)
*
equation zeqn *
# ddp{1 to nlags} ddm{0 to nlags} constant
*
* Figure out the observable range
*
inquire(reglist) start end
# %rlfromtable(%eqntable(zeqn)) %rlfromtable(%eqntable(yeqn))
*
* Starting values
*
filter(type=hp) y start-nlags end y_hp
set y_gap = y-y_hp
filter(type=hp) u start-nlags end u_hp
set u_gap = u-u_hp

lin y_gap
# u_gap{1}
compute phi1  = %beta(1)
compute lnvyc = log(%seesq)

lin ddp
# u_gap{1} ddp{1 to nlags} ddm{0 to nlags} constant
compute rho2 = %beta(1)
compute sup1 = %beta(2), sup2 = %beta(3), sup3 = %beta(4)
compute sup4 = %beta(5), sup5 = %beta(6), sup6 = %beta(7), sup7 = %beta(8)
compute kappa= 1000.0*%beta(9)
compute lnvh = log(%seesq)

diff(diffs=2) y_hp / ddy_hp
stat(noprint) ddy_hp start-nlags end
compute lnvbeta=log(%variance)
compute [real] lnvp=-20.0

diff(diffs=2) u_hp / ddu_hp
stat(noprint) ddu_hp start-nlags end
compute lnvzeta=log(%variance)
compute [real] lnvn=-20.0
*
lin u_gap
# u_gap{1 to 2}
compute lnvuc = log(%seesq)
compute delt1 = %beta(1), delt2 = %beta(2)
*
* Initial conditions for SSM
*
declare vector x0(nstates)
compute x0=%const(0)
declare symmetric v0(nstates,nstates)
compute v0=infinity*%identity(nstates)

nonlin phi1 rho2 delt1 delt2 $
       lnvh lnvp lnvbeta lnvyc lnvn lnvzeta lnvuc $
       sup1 sup2 sup3 sup4 sup5 sup6 sup7 kappa
*
dec rect a f m w
dec symm sw sv
*
* This sets up the input matrices for the DLM which are fixed across time
*
function DLMSetup
compute a = ||$
1,1,0,0,0,0,0,0|$
0,1,0,0,0,0,0,0|$
0,0,0,0,0,0,phi1,0|$
0,0,1,0,0,0,0,0|$
0,0,0,0,1,1,0,0|$
0,0,0,0,0,1,0,0|$
0,0,0,0,0,0,delt1,delt2|$
0,0,0,0,0,0,1,0||
compute m = ||$
1,0,1,0,0,0,0,0|$
0,0,0,0,1,0,1,0|$
0,0,0,0,0,0,0,rho2||
compute w = ||$
0,0,0,0,0,0,0,0| $
0,0,0,0,0,0,0,0| $
sup1,sup2,sup3,sup4,sup5,sup6,sup7,.001*kappa||
compute f=||$
1,0,0,0,0,0|$
0,1,0,0,0,0|$
0,0,1,0,0,0|$
0,0,0,0,0,0|$
0,0,0,1,0,0|$
0,0,0,0,1,0|$
0,0,0,0,0,1|$
0,0,0,0,0,0||
compute sw=%diag(%exp(||lnvp,lnvbeta,lnvyc,lnvn,lnvzeta,lnvuc||))
compute sv=%diag(||0.0,0.0,exp(lnvh)||)
end
*
* Defines the observable
*
dec frml[vector] yf
*frml yf = %eqnxvector(yeqn,t)-w*%eqnxvector(zeqn,t)
frml yf = || y,u,ddp||


dec frml[vector] z
frml z = || ddp{1}, ddp{2}, ddp{3}, ddm, ddm{1},ddm{2},ddm{3},constant||


dec frml[vector] m2
frml m2 =  w * z
*
* This sequence reproduces the results in the paper. The initial pegging
* of the lnvzeta parameter (which governs the change in the NAIRU trend)
* prevents the estimation from heading towards a second mode with a much
* higher value for that parameter. (That mode has only a slightly
* smaller likelihood, but implies a NAIRU which tracks the observed
* unemployment almost exactly.)
*
* For reasons we have yet to determine, it doesn't work to shift to BFGS
* for the second set of iterations.
*
nonlin(parmset=ssmparms) phi1 rho2 delt1 delt2
nonlin(parmset=regparms) sup1 sup2 sup3 sup4 sup5 sup6 sup7 kappa
nonlin(parmset=variances) lnvh lnvp lnvbeta lnvyc=-50.0 lnvn lnvzeta lnvuc
nonlin(parmset=pegs) lnvzeta=-18.5
dlm(start=DLMSetup(),parmset=ssmparms+regparms+variances+pegs,y=yf,a=a,c=tr(m),mu=m2,f=f,sw=sw,sv=sv,$
 x0=x0,sx0=v0,condition=exclude, method=simplex,iters=50,noprint) start end

dlm(start=DLMSetup(),parmset=ssmparms+regparms+variances,y=yf,a=a,c=tr(m),mu=m2,f=f,sw=sw,sv=sv,$
 x0=x0,sx0=v0,condition=exclude, method=simplex,iters=100) start end
*
* This computes the Kalman smoothed estimates of the states at the final estimates.
*
dlm(start=DLMSetup(),parmset=ssmparms+regparms+variances,y=yf,a=a,c=tr(m),mu=m2,f=f,sw=sw,sv=sv,$
 x0=x0,sx0=v0, type=smooth,likelihood=loglik,vhat=vhat) start end xstates vstates
*
* This is a more technically correct set of estimates. The state space
* model has four unit roots in eight states. Using a fully diffuse prior
* (which is what is done above) produces a decided difference in the
* first forty or fifty observations as the high variance on the four
* stationary states resolves out. This has almost no effect on the
* smoothed values, but the filtered values are what determine the
* coefficient estimates.
*
* BFGS *does* work with this.
*
dlm(start=DLMSetup(),parmset=ssmparms+regparms+variances+pegs,y=yf,a=a,c=tr(m),mu=m2,f=f,sw=sw,sv=sv,$
 presample=ergodic,condition=exclude, method=simplex,iters=50) start end

dlm(start=DLMSetup(),parmset=ssmparms+regparms+variances,y=yf,a=a,c=tr(m),mu=m2,f=f,sw=sw,sv=sv,$
 presample=ergodic,condition=exclude, method=bfgs,iters=200) start end

dlm(start=DLMSetup(),parmset=ssmparms+regparms+variances,y=yf,a=a,c=tr(m),mu=m2,f=f,sw=sw,sv=sv,$
 presample=ergodic, type=smooth,likelihood=loglik,vhat=vhat) start end xstates vstates
*
* Pull out the smoothed estimates of the NAIRU and potential GDP. Graph these
* against the actual unemployment and GDP.
*
set nairu start end = xstates(t)(5)
set yp    start end = xstates(t)(1)
*
spgraph(vfields=1,hfields=2,footer="Smoothed Series")
graph(hlabel="Output") 2
# y
# yp
graph(hlabel="Unemployment") 2
# u
# nairu
spgraph(done)
*
* Pull out the smoothed estimates of the local trend rates for GDP and U
*
set ytrend start end = xstates(t)(2)
diff yp / dyp
set utrend start end = xstates(t)(6)
diff nairu / dnairu
spgraph(vfields=1,hfields=2,footer="Smoothed Series")
graph(hlabel="Trend in Output") 2
# dyp
# ytrend
graph(hlabel="Trend in Unemployment") 2
# dnairu
# utrend
spgraph(done)
*
* Pull out the smoothed estimates of the gap. Compare with the gaps
* generated by univariate HP filters.
*
set ygap start end = xstates(t)(3)
set ugap start end = xstates(t)(7)
spgraph(vfields=1,hfields=2,footer="Cyclical Series")
graph(hlabel="Output") 2
# y_gap
# ygap
graph(hlabel="Unemployment") 2
# u_gap
# ugap
spgraph(done)
*
* Pull out the smoothed residual in the inflation measurement equation.
* The fitted value (regression component) will be the difference between
* this and the actual ddp series.
*
set pres start end = vhat(t)(3)
set pfit start end = ddp-pres
spgraph(footer="Phillips Curve",vfields=1,hfields=2)
graph(key=none,hlabel="Actual vs Fit") 2
# ddp
# pfit
graph(key=none,hlabel="Residual")
# pres
spgraph(done)





I hope that the codes can be directly written by using new feature.
And add more explanatory comments due to its complex.

Best reagrd
Hardmann

Re: Fabiani-Mestre 2004 Replication

Posted: Sat Jun 30, 2012 3:59 am
by hardmann
Dear Tom:

The comments tell six DLM command function. However, these are descriptive rather than explanatory.
As for freshman to RATS, me, investigating replicating pressed paper has one destination, to master RATS by replicating example.

I can understan very command by reviewing comments and reference. But I can not know why and how can deal with such problem in aonther case.

Hardmann

Re: Fabiani-Mestre 2004 Replication

Posted: Fri Feb 07, 2014 10:04 pm
by TomDoan
hardmann wrote:Dear Tom:

Under your recommand, I directly use f and mu option in DLM.
I modify frml yf = || y,u,ddp|| and add
dec frml[vector] z
frml z = || ddp{1}, ddp{2}, ddp{3}, ddm, ddm{1},ddm{2},ddm{3},constant||
dec frml[vector] m2
frml m2 = w * z

and then add option mu=m2 in six DLM commands

All codes of baseline model is as follows, it is right? :
Yes. And an obvious way to check is to run the before and after and see if you get the same results.

Fabiani-Mestre 2004 Replication

Posted: Fri Jul 16, 2021 5:39 pm
by atarca
Dear Tom,

I tried to run ErrorBands.rpf of Fabiani & Mestre(2004) with annual series. However, I got the following error warning:

The Error Occurred At Location 286, Line 12 of loop/block
## DLM1. Rank of Prediction Error Variance < Number of Observables
The Error Occurred At Location 717, Line 26 of loop/block
## DLM1. Rank of Prediction Error Variance < Number of Observables

I appreciate if you would kindly show me a way to solve the problem.

Code: Select all

*
* Replication for Fabiani & Mestre(2004), "A system approach for
* measuring the euro area NAIRU," Empirical Economics, vol. 29, no. 2,
* pages 311-341
*
* Error Bands for baseline model
* For numerical reasons, this estimates the variances in log form and
* scales up the constant in the inflation equation by a factor of 1000.
*
calendar(a) 1930
allocate 2017:1
*
* options
*
compute [integer] nstates=8             ;*** number of states
compute [integer] exclude=nstates       ;*** number of initial obs to drop
compute [integer] nlags=3               ;*** number of lags in measurement equ
*
* read data
*
open data C:\Users\Pc\Desktop\NAIRU.RAT
data(format=rats) / urx yer pcd mtd1 mtd2 mtd3 mtd4

log pcd   / lpcd
log yer   / lyer
log mtd1   / lmtd1
log mtd2   / lmtd2
log mtd3   / lmtd3

diff lpcd / dlpcd
diff lyer / dlyer
diff lmtd1 / dlmtd1
diff lmtd2 / dlmtd2
diff lmtd3 / dlmtd3

diff dlpcd / ddlpcd
diff dlyer / ddlyer
diff dlmtd1 / ddlmtd1
diff dlmtd2 / ddlmtd2
diff dlmtd3 / ddlmtd3

*** data
set ddp = ddlpcd
set ddm = ddlmtd1
*set ddm = ddlmtd2
*set ddm = ddlmtd3
*set ddm = mt4
set y = lyer
set u = urx
*
* Observables from measurement equation(s)
*
equation yeqn *
# y u ddp
*
* Co-states from measurement equation(s)
*
equation zeqn *
# ddp{1 to nlags} ddm{0 to nlags} constant
*
* Figure out the observable range
*
inquire(reglist) start end
# %rlfromtable(%eqntable(zeqn)) %rlfromtable(%eqntable(yeqn))
*
* Starting values
*
filter(type=hp) y start-nlags end y_hp
set y_gap = y-y_hp
filter(type=hp) u start-nlags end u_hp
set u_gap = u-u_hp

lin y_gap
# u_gap{1}
compute phi1  = %beta(1)
compute lnvyc = log(%seesq)

lin ddp
# u_gap{1} ddp{1 to nlags} ddm{0 to nlags} constant
compute rho2 = %beta(1)
compute sup1 = %beta(2), sup2 = %beta(3), sup3 = %beta(4)
compute sup4 = %beta(5), sup5 = %beta(6), sup6 = %beta(7), sup7 = %beta(8)
compute kappa= 1000.0*%beta(9)
compute lnvh = log(%seesq)

diff(diffs=2) y_hp / ddy_hp
stat(noprint) ddy_hp start-nlags end
compute lnvbeta=log(%variance)
compute [real] lnvp=-20.0

diff(diffs=2) u_hp / ddu_hp
stat(noprint) ddu_hp start-nlags end
compute lnvzeta=log(%variance)
compute [real] lnvn=-20.0
*
lin u_gap
# u_gap{1 to 2}
compute lnvuc = log(%seesq)
compute delt1 = %beta(1), delt2 = %beta(2)

nonlin phi1 rho2 delt1 delt2 $
       lnvh lnvp lnvbeta lnvyc lnvn lnvzeta lnvuc $
       sup1 sup2 sup3 sup4 sup5 sup6 sup7 kappa
*
dec rect a f m w
dec symm sw sv
*
* This sets up the input matrices for the DLM which are fixed across time
*
function DLMSetup
compute a = ||$
1,1,0,0,0,0,0,0|$
0,1,0,0,0,0,0,0|$
0,0,0,0,0,0,phi1,0|$
0,0,1,0,0,0,0,0|$
0,0,0,0,1,1,0,0|$
0,0,0,0,0,1,0,0|$
0,0,0,0,0,0,delt1,delt2|$
0,0,0,0,0,0,1,0||
compute m = ||$
1,0,1,0,0,0,0,0|$
0,0,0,0,1,0,1,0|$
0,0,0,0,0,0,0,rho2||
compute w = ||$
0,0,0,0,0,0,0,0| $
0,0,0,0,0,0,0,0| $
sup1,sup2,sup3,sup4,sup5,sup6,sup7,.001*kappa||
compute f=||$
1,0,0,0,0,0|$
0,1,0,0,0,0|$
0,0,1,0,0,0|$
0,0,0,0,0,0|$
0,0,0,1,0,0|$
0,0,0,0,1,0|$
0,0,0,0,0,1|$
0,0,0,0,0,0||
compute sw=%diag(%exp(||lnvp,lnvbeta,lnvyc,lnvn,lnvzeta,lnvuc||))
compute sv=%diag(||0.0,0.0,exp(lnvh)||)
end
*
* Defines the observable
*
dec frml[vector] yf
frml yf = %eqnxvector(yeqn,t)-w*%eqnxvector(zeqn,t)
*
nonlin(parmset=ssmparms) phi1 rho2 delt1 delt2
nonlin(parmset=regparms) sup1 sup2 sup3 sup4 sup5 sup6 sup7 kappa
nonlin(parmset=variances) lnvh lnvp lnvbeta lnvyc=-50.0 lnvn lnvzeta lnvuc
compute allparms=ssmparms+regparms+variances
nonlin(parmset=pegs) lnvzeta=-18.5
*
dlm(start=DLMSetup(),parmset=allparms+pegs,y=yf,a=a,c=tr(m),f=f,sw=sw,sv=sv,$
 presample=ergodic,condition=8,$
 method=simplex,iters=200) start end
dlm(start=DLMSetup(),parmset=allparms,y=yf,a=a,c=tr(m),f=f,sw=sw,sv=sv,$
 presample=ergodic,condition=8,$
 method=bfgs,iters=200) start end
*
* Instead of bootstrapping, this does independence chain
* Metropolis-Hastings MCMC
*
compute betamean=%beta,fxx=%decomp(%xx)
*
* Keep track of last values for MH sampling
*
compute logplast=%logl,logqlast=0.0,betadraw=%beta
*
* This does independence MH
*
compute nburn =100
compute ndraws=5000
*
compute accept=0
*
* These are used for the first moment and second moments of the NAIRU
* estimates
*
set first  = 0.0
set second = 0.0
*
infobox(action=define,progress,lower=-nburn,upper=ndraws) "Independence MH"
do draw=-nburn,ndraws
   *
   * draw beta from the normal approximation. (tail fattening doesn't
   * seem to help)
   *
   compute beta=betamean+%ranmvnormal(fxx)
   compute logqtest=%ranlogkernel()
   *
   * Evaluate the likelihood function at the drawn value
   *
   compute %parmspoke(allparms,beta)
   dlm(start=DLMSetup(),parmset=allparms,y=yf,a=a,c=tr(m),f=f,sw=sw,sv=sv,$
     presample=ergodic,condition=8) start end
   compute logptest=%logl
   *
   compute alpha  =exp(logptest-logplast+logqlast-logqtest)
   if %uniform(0.0,1.0)<alpha
      compute logqlast=logqtest,logplast=logptest,accept=accept+1,betadraw=beta
   infobox(current=draw) %strval(100.0*accept/(draw+nburn+1),"##.#")
   if draw<=0
      next
   *
   * Do the bookkeeping here. Do a conditional simulation to get a
   * simulated NAIRU
   *
   dlm(start=DLMSetup(),parmset=allparms,y=yf,a=a,c=tr(m),f=f,sw=sw,sv=sv,$
     presample=ergodic,condition=8,type=csim) start end xstates
   set first  start end = first+xstates(t)(5)
   set second start end = second+xstates(t)(5)^2
end do draw
infobox(action=remove)
*
set first  = first/ndraws
set second = sqrt(second/ndraws-first^2)
set lower  = first-1.0*second
set upper  = first+1.0*second
*
graph(footer="Error bands (One Std Dev) for NAIRU") 4
# u
# first start end
# lower start end 3
# upper start end 3


Re: Fabiani-Mestre 2004 Replication

Posted: Tue Aug 03, 2021 12:59 pm
by TomDoan
There are a lot of tweaks in the Fabiani-Mestre model (and most similar models) which are specific to the particular data set. (For instance, the PEGS is to override a problem with one of the variances going zero). If you post the data set, I can take a closer look.

Re: Fabiani-Mestre 2004 Replication

Posted: Sat Aug 21, 2021 6:48 am
by atarca
TomDoan wrote:There are a lot of tweaks in the Fabiani-Mestre model (and most similar models) which are specific to the particular data set. (For instance, the PEGS is to override a problem with one of the variances going zero). If you post the data set, I can take a closer look.
Thanks Tom.
Here's my data set.
Cheers.
Tarkan