# Local linear trend estimation

I’m trying to familiarise myself with estimating Unobserved Component models with Dynare. As an exercise I am trying to simulate and estimate simple models that would normally be used for output gap estimation. Below are 2 sample model blocks for models V1 and V2 respectively. V2 is a standard local linear trend (eg see Harvey and Jaeger 1993)

// 1. Model equations V1
Y = T + eps_1;
T = T(-1) + eps_2;
end;

// 1. Model equations V2
Y = T + eps_1;
T = T(-1) + 1*d(-1) + eps_2;
d = d(-1) + eps_3;
end;

The simulation all works fine. For estimation however, when I go from model V1 to model V2, the parameters (eps_1, eps_2 and eps_3) are successfully estimated, but I get the below error (note that this occurs on the last line of dynare.m).

Any thoughts what could be causing the problem after such a simple change to the model? Note also that if I change the coeffient on d(-1) in the T equation to 0.5 the error is no longer displayed.

Many thanks,
Dynaresaur

“Error using +
Matrix dimensions must agree.

Error in missing_DiffuseKalmanSmootherH1_Z (line 128)
a(:,:,t+1) = T*(a(:,:,t)+Kstar(:,:,t)*v(:,t));

Error in DsgeSmoother (line 164)
[alphahat,epsilonhat,etahat,ahat,P,aK,PK,decomp] = missing_DiffuseKalmanSmootherH1_Z(ST, …

Error in dynare_estimation_1 (line 920)
[atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp] =
DsgeSmoother(xparam1,dataset_.info.ntobs,dataset_.data,dataset_.missing.aindex,dataset_.missing.state);

Error in dynare_estimation (line 70)
dynare_estimation_1(var_list,dname);

Error in UC_HP_filter_replic_v15a (line 116)
dynare_estimation(var_list_);

Error in dynare (line 120)
evalin(‘base’,fname) ;”

Dear Prof Pfeifer, Thanks for your response and apologies for my delayed reply.

I resolved the stated issue by re-writing the model as follows, where Dd = d - d(-1):

// 1. Model equations V2
Y = T + eps_1;
(T-T(-1))-(T(-1)-T(-2))= Dd(-1) + eps_2-eps_2(-1);
Dd = eps_3;

Am not sure why this works – perhaps Dynare doesn’t like having both I(1) and I(2) variables in the model?

Following on from this, I have augmented the model by modelling the cycle as an AR(2) (see code below). This creates a further problem: the estimates of the autoregressive parameters are quite far off from the paramter values used to generate the data (r1=0.2 and r2=0.1). The mode check plots suggest this relates to stability issues. Note that if I model the cycle as an AR(1) process, the estimation goes through fine.

Any thoughts that could shed light on what’s happening here would be much appreciated.

Many thanks,
D

// 0. Variable definitions
var T Y Dd C;
varexo eps_1 eps_2 eps_3;

parameters s1 s2 s3 r1 r2;
s1 = 0.1;
s2 = 0.1;
s3 = 0.1;
r1 = 0.2;
r2 = 0.1;

model;

// 1. Model equations
Y = T + C;
C = r1C(-1) + r2C(-2) + eps_1;
(T-T(-1))-(T(-1)-T(-2))= Dd(-1) + eps_2-eps_2(-1);
Dd = eps_3;
end;

T = 1;
Y = 1;
Dd=0;
C = 0;
end;

// 3.1 Simulation

shocks;
var eps_1;
stderr s1;
var eps_2;
stderr s2;
var eps_3;
stderr s3;
end;

stoch_simul(periods=2501, order=1, nograph);
save obs_data Y;
/*
*/

//3.2 ML Estimation

estimated_params;
stderr eps_1, 0.09, 0, 1;
stderr eps_2, 0.09, 0, 1;
stderr eps_3, 0.09, 0, 1;
r1, 0.1, 0, 0.99;
r2, 0.1, 0, 0.99;
end;

varobs Y;

/*
observation_trends;
Y (0);
end;
*/

estimation(datafile=obs_data, presample=1, first_obs=1, mode_compute=4, mode_check, diffuse_filter);

UPDATE

I tried to resolve the above AR(2) instability issue using the nice approach laid out in this post: Estimation AR(2)-process/Joint prior distribution

This seems to work if I only estimate the AR coefficients. However, when I attempt to estimate the variances in addition then estimates of the AR coefficents (calculated indirectly from the roots) are no longer close to the values used in the simulation.

Code is copied below. Any insight would be much appreciated.

var C Y T Dd;
varexo eps_1 eps_2 eps_3;

parameters root1 root2;

//rho1=1.5;
//rho2=-0.6;
root1=0.95; //root1=1.5/2+sqrt((1.5/2)^2+(-0.6))
root2=0.55; //root1=1.5/2-sqrt((1.5/2)^2+(-0.6))

model;
// parameter conversion

# rho2= - root1*root2;

// model equation
Y = T + C;
C = rho1C(-1)+rho2C(-2)+ eps_1;
(T-T(-1))-(T(-1)-T(-2))= Dd(-1) + eps_2-eps_2(-1);
Dd = eps_3;
end;

T = 1;
Y = 1;
Dd=0;
C = 0;
end;

shocks;
var eps_1; stderr 0.1;
var eps_2; stderr 0.1;
var eps_3; stderr 0.1;
end;

stoch_simul(periods=2501, order=1);
save d_obs Y;

//3.2 ML Estimation

estimated_params;
stderr eps_1, 0.01, 0, 1;
stderr eps_2, 0.01, 0, 1;
//stderr eps_3, 0.01, 0, 1;
root1, 0.95, -0.9999, 0.9999;
root2, 0.55, -0.9999, 0.9999;
end;

varobs Y;

estimation(datafile=d_obs, presample=4, first_obs=1, mode_compute=4, mode_check, diffuse_filter); // simulated data (MLE)

Since the second issue I have encountered is different from the one mentioned in the original post I have reposted it here Estimation AR(2)-process/Joint prior distribution so that all the material related to AR(2) stability problems is in one place.

There is an identification issue as outlined in my response to the linked post above.

Could you please try the original model with the unstable version of Dynare and see whether you get the same crash. If yes, please provide me with the mod-file that crashes.

With regards to the first message in this chain, isn’t the problem in line 128 where the matrix “a” is referred to as though it is three dimensional whereas it was originally defined as a two dimensional (mm, smpl+1) matrix?

Exactly, it has been fixed in the unstable version in github.com/DynareTeam/dynare/commit/42ecfa382f555a2d9eaeec792223844ad8c3d9ab