Lead_lag_incidence

Hello,

I used dynare to solve a 65-variable DSGE model. I just noticed that dynare is not registering the appropriate lag structure for some variables. For instance, two variables appear in lags 3 and 4 (these are shown correctly in dynare solution printout!) but the command M_.lead_lag_incidence is not registering a positive number for these two variables in the lags 3 and 4, but instead it is registering zeros. This is puzzling because there is nothing special about those two variables in my model.

Please, could you give some hint on what is possibly going on with the command M_.lead_lag_incidence? Is there any unfixed bug?

Thank you and my best regards,

nsouzas

Hi,

Are you using Dynare 4.0.4, or the snapshot?

Because in the snapshot, we recently made an important change: variables with a lead > 1 or a lag > 1 are replaced by auxiliary variables.

For example, if you have x(-2) in your model, it will be replaced by aux1(-1), where aux1=x(-1).

And if you you have x(-3), it will be replaced by aux2(-1), where aux2=aux1(-1) and aux1=x(-1).

This also happens for lag.

The idea is to have only one lead and one lag in the transformed model.

So if you are using the snapshot, this is probably the cause of what you observe.

Best,

Dear Sébastien,

Thanks a lot for your previous reply.

Yes, I am using Dynare 4.0.4. Please, is there a structure collecting all auxiliary variables in this version?

Also, is it possible that M_.lead_lag_incidence has a bug? I had the same problem (i.e., M_.lead_lag_incidence is not registering all leads and lags appropriately) with a completely different model. I checked and re-checked and could not find a way out of it. I am pretty sure I am not making any confusion about it.

Sorry for bothering you again with this.

My best,

nsouzas

Dear Sébastien,

Thanks a lot for your previous reply.

Yes, I am using Dynare 4.0.4. Please, is there a structure collecting all auxiliary variables in this version?

Also, is it possible that M_.lead_lag_incidence has a bug? I had the same problem (i.e., M_.lead_lag_incidence is not registering all leads and lags appropriately) with a completely different model. I checked and re-checked and could not find a way out of it. I am pretty sure I am not making any confusion about it.

Sorry for bothering you again with this.

My best,

nsouzas

There is no auxiliary var in Dynare 4.0.4. This was only introduced in the snapshot.

Of course, I can’t rule out a bug in M_.lead_lag_incidence, but we are not aware of any. Please give more details (for example posting you MOD file), I can’t help without further info.

Best,

Dear Sébastien,

Below is the .mod file as you requested. Let me save you some time with the following information. There are two variables with problems: “q” - real exchange rate and “mc” - marginal cost. In the dynare ordering of endogenous variables, these two variables are in positions 19 and 29, respectively. Both variables should appear in lags 1 to 5 but the command lead_lag_incidence is plugging zeros in the entries corresponding to lags 2 and 3 for both variables.

Here is what I think is going on. Those two variables do not appear in lags 2 and 3 explicitly in the model. However, the model solution (policy function) printed out by dynare on my screen shows that they indeed appear in lags 2 and 3. Moreover, inspecting the corresponding IRFs, it makes all sense that in the reduced-form solution those two variables have lags 2 and 3. In summary, it appears that dynare correctly displays the lag structure of the policy function, but the lead_lag_incidence command does not necessarily registers all lags that appear in the policy function. Instead, it only registers the lags that appear in the original model. In my model, since the variables q and mc have truncated lags in the original model but not in the reduced-form solution, the lags missing in the original model are not registered by the lead_lag incidence. If this is true, is there a way to recover all lags of all endogenous variables as they appear in the reduced-form solution (policy function)? I am most interested in the lag structure as they appeard in the policy function and not as they appear in the original model.

Sorry again for bothering you with this.

All my best,

nsouzas

// MEDIUM-SIZE DSGE MODEL
// VERSION: DECEMBER 4, 2009

// 1. VARIABLES
var y c c_O c_RT inv g x m m_I m_Y nx_y y_H y_I k n b_y_RW b_y g_y;
var q q_K q_I q_M q_A q_A_0 q_F s_B_RW w r_K mc r rr upsilon_M upsilon_A upsilon_F pie pie4 pie_M pie4_M pie_A pie4_A pie_F pie4_F pie_Y;
var y_RW a_RW q_M_RW r_RW pie_RW pie4_RW;
var pie_bar s_y_bar s_B g_Z;
var z_B_RW z_I z_X z_MI z_MY z_A z_P z_W z_R z_G z_Q z_D;
varexo e_Y_RW e_A_RW e_M_RW e_R_RW e_Pie_RW e_B e_Pie_bar e_S_bar e_Z e_B_RW e_I e_X e_MI e_MY e_A e_P e_W e_R e_G e_Q e_D;

// 2. PARAMETERS
// PREFERENCES:
parameters beta kappa varkappa sigma eta epsilon_W psi_A_RW psi_B_RW;
// TECHNOLOGY:
parameters alpha delta delta_I varpi_I epsilon_I vartheta_I epsilon_H varpi_Y epsilon_Y vartheta_Y epsilon_Y_RW vartheta_Y_RW iota_M;
// POLICY:
parameters gamma_R gamma_Pie gamma_Y gamma_B gamma_G gamma_S;
// PRICE RIGIDITY:
parameters theta_M omega_M theta_W omega_W theta_F omega_F chi_A upsilon1_A upsilon2_A upsilon3_A;
// STEADY STATE RELATIONS:
parameters gZ varpi_C varpi_A s_C s_I s_G s_X s_M s_M_I s_Y_I s_H I_K R_RW R S_B_RW S_B Q_M Pie_bar B_y B_y_RW Pie_bar_RW Pie_Y Y_D_H;
// SHOCKS:
parameters rho_Y_RW rho_A_RW rho_M_RW rho_R_RW rho_Pie_RW;
parameters rho_Pie_bar rho_S_bar rho_B rho_Z;
parameters rho_B_RW rho_I rho_X rho_MI rho_MY rho_A rho_P rho_W rho_R rho_G rho_Q rho_D;
// REDUCED-FORM:
parameters alpha_N beta_hat kappa_hat varpi1_H varpi2_H varpi1_I varpi2_I varpi_D lambda1_B lambda1_B_RW lambda2_B_RW lambda3_B_RW;
parameters lambda_M lambda1_W lambda2_W lambda3_W lambda4_W lambda_F lambda0_A lambda1_A_0 lambda1_A_1 lambda1_A_2 lambda1_A_3 lambda2_A_0 lambda2_A_1 lambda2_A_2 lambda2_A_3;

// PREFERENCES
beta = 0.980;
kappa = 0.800;
varkappa = 0.250;
sigma = 2.000;
eta = 0.350;
epsilon_W = 3.000; // implies wage markup of 50%
psi_A_RW = 0.672;
psi_B_RW = 0.040;

//TECHNOLOGY
alpha = 0.400;
delta = 0.025;
delta_I = 5.000;
varpi_I = 0.850;
epsilon_I = 1.300;
vartheta_I = 5.000;
epsilon_H = 11.00;
varpi_Y = 0.850;
epsilon_Y = 1.300;
vartheta_Y = 5.000;
epsilon_Y_RW = 5.000;
vartheta_Y_RW= 8.000;
iota_M = 0.500;

// POLICY
gamma_R = 0.682;
gamma_Pie = 1.523;
gamma_Y = 0.040;//0.839;
gamma_B = 0.300;//0.170;
gamma_S = 2.000;//0.500;
gamma_G = gamma_S/(1+gamma_S);//0.800;//0.600;

// PRICE RIGIDITY
theta_M = 0.800;
omega_M = 0.500; // indexation to past CPI inflation , (1-omega_M) - index. to past Pie_M
theta_W = 0.900;
omega_W = 0.500; // indexation to past wage inflation, (1-omega_W) - index. to past CPI inflation
theta_F = 0.500;
omega_F = 0.500;
chi_A = 1;//0.750;
upsilon1_A = 0.700;
upsilon2_A = 0.100;
upsilon3_A = 1-upsilon1_A-upsilon2_A;

// STEADY STATE RELATIONS
gZ = 1.010; // quarterly GDP growth rate of 1%
varpi_C = 0.400;
varpi_A = 0.350;
s_C = 0.555;
s_I = 0.147;
s_G = 0.176;
s_X = 0.122;
s_M = 0.100;
varpi_D = 1-s_M;
s_M_I = 0.250; // share of imported capital good in total investment
s_Y_I = 0.100;
s_H = s_C + s_G + s_X + s_Y_I;
I_K = 0.025;
S_B_RW = 1.016;
S_B = 1.000;
R = 1.042;
R_RW = 1.009;
B_y_RW = -0.8410.421;
B_y = 1.87
0.55;
Q_M = 1.000;
Y_D_H = 1.000;
Pie_Y = 1.011;
Pie_bar = 1.011;
Pie_bar_RW= 1.000;

// SHOCKS
rho_Y_RW = 0.500; // 0.257;
rho_A_RW = 0.800; // 0.640;
rho_M_RW = 0.500;
rho_R_RW = 0.500; // 0.848;
rho_Pie_RW = 0.500;
rho_Pie_bar = 0.500; // 0.937;
rho_S_bar = 0.500; // 0.915;
rho_B = 0.500; // 0.000;
rho_Z = 0.500; // 0.000;
rho_B_RW = 0.500; // 0.867;
rho_I = 0.500; // 0.280;
rho_X = 0.500; // 0.000;
rho_MI = 0.500; // 0.000;
rho_MY = 0.500; // 0.000;
rho_A = 0.500; // 0.800;
rho_P = 0.500; // 0.000;
rho_W = 0.500; // 0.124;
rho_R = 0.010;
rho_G = 0.010;
rho_Q = 0.500; // 0.000;
rho_D = 0.500; // 0.985;

// REDUCED-FORM PARAMETERS
alpha_N = 1/(1-0.25); // 25% of labor effort is overhead labor
beta_hat = beta*(gZ)^(1-sigma);
kappa_hat = kappa/gZ;
varpi1_H = varpi_D/(1-vartheta_Y*(1-varpi_D));
varpi2_H = (1-varpi_D)/(1-vartheta_Y*(1-varpi_D));
varpi1_I = 1 - (1-varpi_I)((1+iota_M(R_RWS_B_RW-1))Q_M)^(1-epsilon_I)/(varpi_I+(1-varpi_I)((1+iota_M(R_RWS_B_RW-1))Q_M)^(1-epsilon_I));
varpi2_I = iota_M
R_RW
S_B_RW/(1+iota_M*(R_RWS_B_RW-1));
lambda1_B = R
S_B/(gZPie_bar);
lambda1_B_RW = Pie_bar
R_RWS_B_RW/(Pie_bar_RWgZPie_Y);
lambda2_B_RW = B_y_RW - iota_M
(R_RWS_B_RW)^2s_M_I;
lambda3_B_RW = R_RWS_B_RWiota_M*(R_RWS_B_RW-1)s_M_I;
lambda_M = (1-theta_M)
(1-theta_M
beta_hat)/theta_M;
lambda1_W = (1-theta_W)(1-theta_Wbeta_hat)/(theta_W*(1+etaepsilon_W)(1+omega_Wbeta_hat));
lambda2_W = omega_W/(1+omega_W
beta_hat);
lambda3_W = beta_hat/(1+omega_Wbeta_hat);
lambda4_W = 1/(1+omega_W
beta_hat);
lambda_F = (1-theta_F)(1-theta_Fbeta_hat)/theta_F;
lambda0_A = 4/(1+Pie_bar^(epsilon_H-1)+Pie_bar^(2*(epsilon_H-1))+Pie_bar^(3*(epsilon_H-1)));
lambda1_A_0 = lambda0_APie_bar^(0(epsilon_H-1));
lambda1_A_1 = lambda0_APie_bar^(1(epsilon_H-1));
lambda1_A_2 = lambda0_APie_bar^(2(epsilon_H-1));
lambda1_A_3 = lambda0_APie_bar^(3(epsilon_H-1));
lambda2_A_0 = epsilon_Hlog(lambda0_A^(epsilon_H-1)Pie_bar^(0(epsilon_H-1)));
lambda2_A_1 = epsilon_H
log(lambda0_A^(epsilon_H-1)Pie_bar^(1(epsilon_H-1)));
lambda2_A_2 = epsilon_Hlog(lambda0_A^(epsilon_H-1)Pie_bar^(2(epsilon_H-1)));
lambda2_A_3 = epsilon_H
log(lambda0_A^(epsilon_H-1)Pie_bar^(3(epsilon_H-1)));

// 3. MODEL
model (linear);

// AGGREGATE DEMAND
// GDP:
y = s_Cc + s_Iinv + s_Gg + s_Xx - s_Mm;
// CONSUMPTION:
c = varpi_C
c_RT + (1-varpi_C)*c_O;
c_O = (kappa_hat/(1+kappa_hat))c_O(-1) + (1/(1+kappa_hat))c_O(+1) - ((1/sigma)(1-kappa_hat)/(1+kappa_hat))(r + s_B - pie(+1)) + ((rho_Z-kappa_hat)/(1+kappa_hat))*g_Z;
c_RT = ((1+eta)/eta)w - (1/eta)(sigma)*c_O ;

// INVESTMENT:
inv = (1/(1+beta_hat))inv(-1) + (beta_hat/(1+beta_hat))inv(+1) - (1/(delta_IgZ^2(1+beta_hat)))(q_I - q_K) - ((1-beta_hatrho_Z)/(1+beta_hat))g_Z + ((1-beta_hatrho_I)/(1+beta_hat))z_I;
q_I = (1-varpi1_I)
(q_M + varpi2_I*(r_RW + s_B_RW) + vartheta_I*(m_I - m_I(-1)-(inv - inv(-1)))-z_MI);
// GOVERNMENT EXPENDITURE:
g = y + (1/s_G)g_y + s_Iq_I - s_M*(q + q_M_RW);
// TRADE BALANCE:
x = y_RW + (1/(1+vartheta_Y_RW*(epsilon_Y_RW-1)))(vartheta_Y_RW(epsilon_Y_RW-1)(x(-1) - y_RW(-1)) + epsilon_Y_RWq + (epsilon_Y_RW-1)z_X);
m = s_M_I
m_I + (1 - s_M_I)m_Y;
m_I = inv + (1/(1+vartheta_I
(epsilon_I-1)))(vartheta_I(epsilon_I-1)(m_I(-1) - inv(-1)) - epsilon_I(q_M - q_I + varpi2_I*(r_RW + s_B_RW)) + (epsilon_I-1)z_MI);
m_Y = y_H + (1/(1+vartheta_Y
(epsilon_Y-1)))(vartheta_Y(epsilon_Y-1)(m_Y(-1) - y_H(-1)) - epsilon_Y(q_M - mc) + (epsilon_Y-1)z_MY);
nx_y = s_X
x - s_Mm - (s_X - s_M)y - s_I(s_X - s_M)q_I - s_M(1 + s_M - s_X)(q + q_M_RW);

// AGGREGATE SUPPLY
// HOME OUTPUT:
y_H = (s_C/s_H)c + (s_Y_I/s_H)y_I + (s_G/s_H)g + (s_X/s_H)x;
y_I = inv + epsilon_I
q_I;
// CAPITAL:
k = (1-I_K)
(k(-1) - g_Z) + I_K
inv;
r_K = (1/(1-alpha
(1-epsilon_Y)))(y_H - k(-1) + (1-epsilon_Y)(1-alpha)w + epsilon_Ymc - (1-epsilon_Y)z_D);
q_K = (beta_hat/gZ)
(1-delta)q_K(+1) + (1-(1-delta)beta_hat/gZ)r_K(+1) - (r + s_B - pie(+1));
// LABOR:
n = (1/alpha_N)
(y_H - (epsilon_Y+alpha
(1-epsilon_Y))w + alpha(1-epsilon_Y)r_K + epsilon_Ymc - (1-epsilon_Y)z_D);
w = w(-1) + lambda1_W
(eta
n + (sigma/(1-kappa_hat))(c_O - kappa_hat(c_O(-1) - g_Z))- w + z_W) + lambda2_W*(w(-1) - w(-2)) + lambda3_W*(w(+1) - w) - (lambda3_W + lambda4_W)(g_Z + pie) + lambda4_W(g_Z(-1) + pie(-1)) + lambda3_W*(rho_Zg_Z + pie(+1));
// MARGINAL COST:
mc = varpi_D
(alphar_K + (1-alpha)w - z_D) + (1-varpi_D)(q_M + vartheta_Y((m_Y - m_Y(-1)) - (y_H - y_H(-1))) - z_MY);
// CPI INFLATION:
pie = varpi_Apie_A + (1-varpi_A)pie_F;
pie4 = pie + pie(-1) + pie(-2) + pie(-3);
pie_F = upsilon_F + lambda_F
(mc - q_F + z_P) + beta_hat
(pie_F(+1) - upsilon_F(+1));
pie4_F = pie_F + pie_F(-1) + pie_F(-2) + pie_F(-3);
upsilon_F = omega_Fpie(-1) + (1-omega_F)pie_bar;
q_F = q_F(-1) + pie_F - pie;
pie_A = pie + q_A - q_A(-1);
pie4_A = pie_A + pie_A(-1) + pie_A(-2) + pie_A(-3);
q_A_0 = q_A_0(-4) + upsilon_A - pie4;
q_A = (1/4)
(lambda1_A_0
(q_A_0 + lambda2_A_0z_P) + lambda1_A_1(q_A_0(-1)-pie + lambda2_A_1z_P) +lambda1_A_2(q_A_0(-2)-pie-pie(-1) + lambda2_A_2z_P) +lambda1_A_3(q_A_0(-3)-pie-pie(-1)-pie(-2) + lambda2_A_3z_P));
upsilon_A = pie4 + chi_A
upsilon2_A*.5*(q+q(-1) - q(-4)-q(-5)) + chi_Aupsilon3_A.5*(mc+mc(-1) - mc(-4)-mc(-5)) - (1-chi_A)*q_A_0(-4) + z_A;

// GDP DEFLATOR INFLATION:
pie_Y = s_I*(q_I - q_I(-1)) - s_M*(q - q(-1) + q_M_RW - q_M_RW(-1)) + pie;
// IMPORTS INFLATION:
pie_M = upsilon_M(-1) + lambda_M*(q + q_M_RW - q_M) + beta_hat*(pie_M(+1) - upsilon_M);
upsilon_M = omega_M*pie + (1-omega_M)*pie_M;
pie4_M = pie_M + pie_M(-1) + pie_M(-2) + pie_M(-3);
q_M = q_M(-1) + pie_M - pie;

// FINANCIAL VARIABLES
q = varkappaq(-1) + (1-varkappa)q(+1) - ((r + s_B - pie(+1)) - (r_RW + s_B_RW - pie_RW(+1))) + z_Q;
b_y_RW= lambda1_B_RW
b_y_RW(-1) + lambda2_B_RW
(r_RW + s_B_RW) + R_RWS_B_RWnx_y - lambda3_B_RW*(m_I + q_M +s_M*(q + q_M_RW) - s_Iq_I - y) + lambda1_B_RWB_y_RW*((q - q(-1)) - (y - y(-1)) + (pie - pie_RW - pie_Y) - g_Z);
s_B_RW = psi_A_RWa_RW - psi_B_RWb_y_RW + z_B_RW;
b_y = lambda1_Bb_y(-1) - lambda1_BB_y*(pie_Y + y - y(-1) + g_Z) + RS_Bg_y + B_y*(r + s_B);
s_B = rho_B*s_B(-1) + e_B;

// GOVERNMENT:
r = gamma_Rr(-1) + (1-gamma_R)(gamma_Pie*(pie4(+4)/4 - pie_bar) + pie_bar + gamma_Yy) + z_R;
rr = r - pie(+1);
pie_bar = rho_Pie_bar
pie_bar(-1) + e_Pie_bar;
g_y = (gamma_G - (1-gamma_G)gamma_S)g_y(-1) - (1-gamma_G)(gamma_Ss_y_bar(-1) + gamma_Bb_y(-1)) + z_G;
s_y_bar = rho_S_bar
s_y_bar(-1) + e_S_bar;

// REST-OF-THE WORLD:
y_RW = rho_Y_RWy_RW(-1) + e_Y_RW;
a_RW = rho_A_RW
a_RW(-1) + e_A_RW;
q_M_RW = rho_M_RWq_M_RW(-1) + e_M_RW;
r_RW = rho_R_RW
r_RW(-1) + e_R_RW;
pie_RW = rho_Pie_RW*pie_RW(-1) + e_Pie_RW;
pie4_RW = pie_RW + pie_RW(-1) + pie_RW(-2) + pie_RW(-3);

// FAKE SHOCKS:
g_Z = rho_Zg_Z(-1) + e_Z;
z_B_RW= rho_B_RW
z_B_RW(-1) + e_B_RW;
z_I = rho_Iz_I(-1) + e_I;
z_X = rho_X
z_X(-1) + e_X;
z_MI = rho_MIz_MI(-1) + e_MI;
z_MY = rho_MY
z_MY(-1) + e_MY;
z_A = rho_Az_A(-1) + e_A;
z_P = rho_P
z_P(-1) + e_P;
z_W = rho_Wz_W(-1) + e_W;
z_R = rho_R
z_R(-1) + e_R;
z_G = rho_Gz_G(-1) + e_G;
z_Q = rho_Q
z_Q(-1) + e_Q;
z_D = rho_D*z_D(-1) + e_D;
end;

// 4. EXOGENOUS SHOCKS
shocks;
var e_Y_RW; stderr 0.00;
var e_A_RW; stderr 0.00;
var e_M_RW; stderr 0.00;
var e_R_RW; stderr 0.00;
var e_Pie_RW; stderr 0.00;
var e_B; stderr 0.00;
var e_Pie_bar; stderr 0.00;
var e_S_bar; stderr 0.00;
var e_Z; stderr 0.00;
var e_B_RW; stderr 0.00;
var e_I; stderr 0.00;
var e_X; stderr 0.00;
var e_MI; stderr 0.00;
var e_MY; stderr 0.00;
var e_A; stderr 0.00;
var e_P; stderr 0.00;
var e_W; stderr 0.00;
var e_R; stderr 0.30;
var e_G; stderr 0.00;
var e_Q; stderr 0.00;
var e_D; stderr 0.00;
end;

// 5. SOLUTION AND SIMULATION
initval;
y = 0;
c = 0;
c_O = 0;
c_RT = 0;
inv = 0;
q_I = 0;
g = 0;
x = 0;
m = 0;
m_I = 0;
m_Y = 0;
nx_y = 0;
y_H = 0;
y_I = 0;
k = 0;
q_K = 0;
r_K = 0;
n = 0;
w = 0;
mc = 0;
pie = 0;
pie4 = 0;
pie_F = 0;
pie4_F = 0;
pie_A = 0;
pie4_A = 0;
upsilon_M = 0;
upsilon_A = 0;
upsilon_F = 0;
q_A = 0;
q_A_0 = 0;
q_F = 0;
pie_Y = 0;
pie_M = 0;
pie4_M = 0;
q_M = 0;
q = 0;
b_y_RW = 0;
s_B_RW = 0;
b_y = 0;
s_B = 0;
r = 0;
rr = 0;
pie_bar = 0;
g_y = 0;
s_y_bar = 0;
y_RW = 0;
a_RW = 0;
q_M_RW = 0;
r_RW = 0;
pie_RW = 0;
pie4_RW = 0;
g_Z = 0;
z_B_RW = 0;
z_I = 0;
z_X = 0;
z_MI = 0;
z_MY = 0;
z_A = 0;
z_P = 0;
z_W = 0;
z_R = 0;
z_G = 0;
z_Q = 0;
z_D = 0;
end;

steady;
check;
stoch_simul(irf=0) ;

Dear Sébastien,

The code you requested is attached.

My best

nsouzas

Hi,

Indeed M_.leag_lag_incidence matrix contains the leads/lags of the original model, not those that appear in the decision rules. So everything is working as expected.

Here is how you can retrieve what you want. This should work with Dynare 4.0.4, but it will not work with the future Dynare 4.1:

k = find(oo_.dr.kstate(:,2) <= M_.maximum_lag+1);
klag = oo_.dr.kstate(k, [1,2]);
state =  oo_.dr.order_var(klag(:,1)), klag(:,2)-M_.maximum_lag-2 ];

Each line of “state” will contain a state variable, i.e. a variable appearing in the decision rules. The first column is the index number of the endogenous (as they appear in M_.endo_names). The second column is the lag.

Best

Dear Sébastian,

Thanks a lot for your tip. It worked beautifully!

My best regards,

nsouzas