Help with multi-sector DSGE code (new user, possible mistakes)

Dear Professor Pfeifer

I am new to Dynare and I am trying to build a three-sector DSGE model with agriculture, industry, and services, including broad money and credit dynamics. I attempted to implement this in Dynare, but I suspect there are mistakes in my code because I encounter errors and the results don’t look correct.

Here is the full code I wrote:

var y,c,c2,c3,c_total pi, i, a,cr, rn, n, m, v, y2, pi2, i2, n2, m2, y3, pi3, i3, n3, m3 e broad_money credit;
var y_total, pi_total, i_total, n_total, m_total, Price_level, d_er, er, i_star;

varexo e_a e_v e_cr;

parameters alpha, beta, theta, sigma, phi, rho, phi_pi, phi_y, rho_a, rho_v, lambda, kappa, psi, epsilon, eta eta_broad_money phi_credit_y, phi_credit_i;
parameters alpha2, sigma2, phi2, eta2, lambda2, kappa2, psi2, rho2;
parameters alpha3, sigma3, phi3, eta3, lambda3, kappa3, psi3, rho3, rho_cr;
parameters omega_A, omega_I, omega_S;

// Sector weights
omega_A = 0.13;  // Agriculture
omega_I = 0.35;  // Industry
omega_S = 0.52;  // Services

// Assign parameters
alpha = 0.30;
epsilon = 1.5;
beta = 0.95;
theta = 0.90;
lambda = 0.00413;
rho = -log(beta);
sigma = 1;
phi = 2;
phi_pi = 1.6;
phi_y = 0.5 / 4;
rho_a = 0.98;
rho_v = 0.77;
rho_cr = 0.96;
eta = 0.08;
eta_broad_money = 2.3;
phi_credit_y = 0.5;  // Sensitivity of credit to output
phi_credit_i = -0.010; // Sensitivity of credit to interest rate
kappa = lambda * (sigma + (phi + alpha) / (1 - alpha));
psi = (1 + phi) * ((sigma + phi + alpha * (1 - sigma))^(-1));

alpha2 = 0.70;
sigma2 = 1;
phi2 = 1;
eta2 = 4;
lambda2 = 0.00316;
rho2 = -log(beta);

kappa2 = lambda2 * (sigma2 + (phi2 + alpha2) / (1 - alpha2));
psi2 = (1 + phi2) * ((sigma2 + phi2 + alpha2 * (1 - sigma2))^(-1));

alpha3 = 0.42;
sigma3 = 1;
phi3 = 1.58;
eta3 = 4;
lambda3 = 0.00530;
rho3 = -log(beta);

kappa3 = lambda3 * (sigma3 + (phi3 + alpha3) / (1 - alpha3));
psi3 = (1 + phi3) * ((sigma3 + phi3 + alpha3 * (1 - sigma3))^(-1));

model;
c = c(+1) - 1 / sigma * (i - pi(+1) - rn);
pi = beta * pi(+1) + kappa * y;
rn = rho + sigma * psi * (rho_a - 1) * a;
i = rho + phi_pi * pi + phi_y * y + v;
y = a + (1 - alpha) * n;
m = pi + y - eta * i;
c = y ;

c2 = c2(+1) - 1 / sigma2 * (i2 - pi2(+1) - rn);
pi2 = beta * pi2(+1) + kappa2 * y2;
i2 = rho2 + phi_pi * pi2 + phi_y * y2 + v;
y2 = a + (1 - alpha2) * n2;
m2 = pi2 + y2 - eta2 * i2;
c2 = y2;

c3 = c3(+1) - 1 / sigma3 * (i3 - pi3(+1) - rn);
pi3 = beta * pi3(+1) + kappa3 * y3;
i3 = rho3 + phi_pi * pi3 + phi_y * y3 + v;
y3 = a + (1 - alpha3) * n3;
m3 = pi3 + y3 - eta3 * i3;
c3 = y3;
// Aggregation using sector weights
c_total = c + c2 + c3;
y_total = omega_A * y + omega_I * y2 + omega_S * y3;
pi_total = omega_A * pi + omega_I * pi2 + omega_S * pi3;
i_total = omega_A * i + omega_I * i2 + omega_S * i3;
n_total = omega_A * n + omega_I * n2 + omega_S * n3;
m_total = omega_A * m + omega_I * m2 + omega_S * m3;
Price_level = pi_total - pi_total(-1);

// **Exchange Rate Equation**
e = er + i_star - Price_level;
i_star = 0;
d_er = er-er(-1);
er = 0;

// Broad money equation
broad_money = Price_level + y_total - eta_broad_money * i_total;

// Private sector credit
credit = phi_credit_y * y_total + phi_credit_i * i_total + e_cr;

a = rho_a * a(-1) + e_a;
v = rho_v * v(-1) + e_v;
cr = rho_cr * cr(-1) + e_cr;

end;

initval;
y = 1; m = 0; n = 0; pi = 0; i = rho; rn = rho; a = 0; v = 0; e_a = 0; e_v = 0; er = 0;
y2 = 1; m2 = 0; n2 = 0; pi2 = 0; i2 = rho2; cr = 0;
y3 = 1; m3 = 0; n3 = 0; pi3 = 0; i3 = rho3;

y_total = omega_A * y + omega_I * y2 + omega_S * y3;
pi_total = omega_A * pi + omega_I * pi2 + omega_S * pi3;
i_total = omega_A * i + omega_I * i2 + omega_S * i3;
n_total = omega_A * n + omega_I * n2 + omega_S * n3;
m_total = omega_A * m + omega_I * m2 + omega_S * m3;
broad_money = pi_total + y_total - eta_broad_money * i_total;
credit = phi_credit_y * y_total + phi_credit_i * i_total;
end;

steady;
check;

shocks;
var e_a; stderr 0.01;
var e_v; stderr 0.01;
var e_cr; stderr 0.01;
end;

//use Dynare capabilities to generate TeX-files of the dynamic and static model
write_latex_static_model;
write_latex_dynamic_model;

// Observable Variables
varobs c_total ;

estimated_params;

// Aggregate demand parameters
alpha, normal_pdf, 0.33, 0.01;          // Capital share
beta, normal_pdf, 0.956, 0.01;           // Discount factor
sigma, normal_pdf, 1.00, 0.01;          // Intertemporal elasticity of substitution

// Taylor Rule parameters
phi_pi, normal_pdf, 1.5, 0.01;           // Inflation coefficient in Taylor rule
phi_y, normal_pdf, 0.125, 0.01;         // Output gap coefficient in Taylor rule

// Monetary policy shock persistence
rho_a, normal_pdf, 0.95, 0.01;          // Persistence of technology shocks
rho_v, normal_pdf, 0.8, 0.01;            // Persistence of monetary policy shocks

// Other structural parameters
lambda, normal_pdf, 0.23, 0.01;         // Slope of Phillips curve
kappa, normal_pdf, 0.10, 0.01;           // Aggregate supply responsiveness
eta, normal_pdf, 0.08, 0.01;            // Money demand elasticity
eta_broad_money, normal_pdf, 2.3, 0.01;  // Broad money elasticity
phi_credit_y, normal_pdf, 0.5, 0.01;     // Sensitivity of credit to output
phi_credit_i, normal_pdf, -0.01, 0.001; // Sensitivity of credit to interest rate

// Sector-specific parameters
alpha2, normal_pdf, 0.70, 0.01;         // Capital share (Sector 2)
sigma2, normal_pdf, 1.00, 0.01;         // Intertemporal elasticity (Sector 2)
phi2, normal_pdf, 1.00, 0.01;           // Price elasticity (Sector 2)
lambda2, normal_pdf, 0.12, 0.005;       // Phillips curve slope (Sector 2)

alpha3, normal_pdf, 0.42, 0.01;         // Capital share (Sector 3)
sigma3, normal_pdf, 1.00, 0.01;         // Intertemporal elasticity (Sector 3)
phi3, normal_pdf, 1.58, 0.01;           // Price elasticity (Sector 3)
lambda3, normal_pdf, 0.22, 0.01;        // Phillips curve slope (Sector 3)

end;

// Estimation command
estimation(datafile=BDGDP, mh_replic=60000, bayesian_irf, forecast=20, mh_conf_sig=0.95, mh_nblocks=2, mh_jscale=3.5, mode_compute=6, mode_check );

// Stochastic simulation
stoch_simul(order=1, irf=50);

My main questions is

Am I setting up the model equations correctly for the three sectors and the aggregation?

Any feedback on what I am doing wrong or how to fix these issues would be greatly appreciated.

Thank you so much for your time and guidance!

Best regards,

Tuhin

You did not provide the data file. But the simulation results do not look too bad. What are the errors you encounter?

1 Like

Dear Professor,

Thank you very much for your kind response.There is no error in the simulation.I submitted this paper to a journal and they are saying that
Comments to the Author:
Unfortunately, the DSGE model developed is not convincing, and the main equations must be corrected before the contribution can be resubmitted elsewhere.

So I don’t understand what are the mistakes in my equations.I am very much worried.If you dont mind I can send you the manuscript as well.Please help me.I have been following your for a long time.And I am your student also.Here I have attached the dataset as well.

Best regards,

Tuhin

BDGDP.xlsx (8.5 KB)

Feedback like that refers to the model setup in your paper, not the final implementation in your code. I will answer your email.

1 Like

Professor,

I am very thankful for your comments.