Dynare Estimation: help

I want to do estimation on Paper “Monetary policy and exchange rate volatility in a small open economy”.

I got the following wrong informaiton

Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.

In missing_DiffuseKalmanSmootherH1_Z at 175
In DsgeSmoother at 197
In dynare_estimation_1 at 836
In dynare_estimation at 89
In gali_monacelliEst at 259
In dynare at 180

However, i could not find the reason. Can anybody help me?

The program is as follows:

// Gali & Monacelli, NBER w.p. 8905, April 2002

// Typed and annotated by Jamie Hall, May 2009
// Dynare 4.0.3

var y_os mc_os ppi_os r_os a_os a ygap ppi_h rnat r y yflex ppi s q e p_h cpi_level;

varexo eps_a_os eps_a;

parameters epsilon rho_a rho_a_os a_shock_correl;
epsilon = 6; // Dixit-Stiglitz parameter for within-sector consumption (4)
rho_a = 0.9;// Parameters of the productivity shocks (p.19)
rho_a_os = 0.9;//parameters epsilon rho_a rho_a_os a_shock_correl;
a_shock_correl = 0.77;

model(linear);
#beta = 0.994; // Pure temporal discount factor
#sigma = 1; // Intertemporal consumption elastiticy
#alpha = 0.4; // Degree of ‘openness’ in the Home economy
#eta = 1; // Elast. of sub. between Home and Foreign goods
#phi = 3; // Labour disutility parameter (7)
#kappa_a = lambda*(phi + (sigma/omega_a)); // Real rigidity; see note to (40)
#theta = 0.75; // Calvo probability
#lambda = (1-(betatheta))(1-theta)/theta; // Coefficient on marginal cost in the Phillips Curve
#omega_a = 1 + alpha*(2-alpha)(sigmaeta - 1); // See note to (25)
#BigTheta_a = sigma*(1-omega_a)/(sigma + phiomega_a); // note to (39)
#BigPhi_a = (1-alpha)/omega_a; // (27)
// Monetary policy in the World economy
#phi_a_os = -(sigma
(1+phi)(1-rho_a_os)) / (phi+sigma); // See (51) and the discussion there
#phi_ppi_os = 1.01;
#BigGamma_a = omega_a
(1+phi)/(sigma+phi*omega_a); // Bottom of p.13

// Note: in Monacelli’s Gauss code, “q” stands for the Terms o’ Trade, whereas
// in the NBER paper it stands for the Real Exchange Rate. I’ve followed the NBER paper.

y_os = y_os(+1) - (r_os - ppi_os(+1))/sigma; // Foreign’s Euler eqn, log-deviation form of (22)

mc_os = (sigma + phi)*y_os - (1+phi)*a_os; // Foreign’s marginal cost, log-deviation form of (32)

ppi_os = betappi_os(+1) + lambdamc_os; // Foreign’s Phillips curve (31)

r_os = phi_ppi_osppi_os(+1) + phi_a_osa_os; // Foreign’s Taylor rule — (51) and see also n. 19;
// equivalently, you can specify “ppi_os=0;”.
a_os = rho_a_os*a_os(-1) + eps_a_os; // Foreign’s technology process

a = rho_aa(-1) + eps_a + a_shock_correleps_a_os; // Home’s technology process

ygap = ygap(+1) - (omega_a/sigma)*(r - ppi_h(+1) - rnat); // Home’s IS curve (41)

ppi_h = betappi_h(+1) + kappa_aygap; // Home’s Phillips curve (40)

rnat = -((sigma*(1+phi)(1-rho_a))/(sigma + phiomega_a))a - phiBigTheta_a*(y_os(+1) - y_os);
// Home’s Wicksellian interest rate (41)

//Home’s monetary policy; comment out all but one of these:

	r = 0.5*r(-1) + 1.5*ppi + 0.2*ygap; 

yflex = BigGamma_aa + BigTheta_ay_os; // Home’s flexprice output deviation (39)

y = yflex + ygap; // Definition of Home output (p. 13)

y = y_os + (omega_a/sigma)*s; // Market clearing (25)

ppi = ppi_h + alpha*(s - s(-1)); // Home CPI inflation (11)

q = (1-alpha)*s; // Real exchange rate (13)

s - s(-1) = e - e(-1) + ppi_os - ppi_h; // Differenced version of (12)

p_h = p_h(-1) + ppi_h; // An identity to pin down the relative price of home goods

cpi_level = cpi_level(-1) + ppi; // " " " " " " consumer price level

end;

steady;
check;

shocks;
var eps_a; stderr 1;
var eps_a_os; stderr 2;
end;

estimated_params;
stderr eps_a_os, inv_gamma_pdf,1.08, 10;
stderr eps_a, inv_gamma_pdf, 2.08, 10;
epsilon, normal_pdf, 6.02, 0.5;
rho_a, beta_pdf, 0.9, 0.1;
rho_a_os, beta_pdf, 0.5, 0.1;
a_shock_correl, beta_pdf, 0.77, 0.1;
end;

varobs y e;
estimation(datafile = simuldataGali1, xls_sheet = Dynare, xls_range =B2:C82, nobs=80, mode_compute=6, mode_check, mh_replic=2000);

The data is attached here.simuldataGali1.xls (24 KB)
001 gali 2005.pdf (709 KB)

Your observation equation is wrong. You are trying to match mean 0 model variables to non-mean 0 data. See Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”

Thank you for your help. I will preprocess data and run the program again.

Dear Sir,

I process the data, use real gdp, exchange rate, take log, and detrend with HP-filter. now the data has mean 0. see attached.

However, the program still run out with the same wrong information. Could you pls. help me in finding the problem?

Many thanks!

Jenny

// Gali & Monacelli, NBER w.p. 8905, April 2002

// Typed and annotated by Jamie Hall, May 2009
// Dynare 4.0.3

var y_os mc_os ppi_os r_os a_os a ygap ppi_h rnat r y yflex ppi s q e p_h cpi_level y_obs e_obs;

varexo eps_a_os eps_a;

parameters epsilon rho_a a_shock_correl;
epsilon = 6; // Dixit-Stiglitz parameter for within-sector consumption (4)
rho_a = 0.9; // Parameters of the productivity shocks (p.19)
a_shock_correl = 0.77;

model(linear);
#beta = 0.994; // Pure temporal discount factor
#sigma = 1; // Intertemporal consumption elastiticy
#alpha = 0.4; // Degree of ‘openness’ in the Home economy
#eta = 1; // Elast. of sub. between Home and Foreign goods
#phi = 3; // Labour disutility parameter (7)
#theta = 0.75; // Calvo probability
#rho_a_os = 0.9;
#lambda = (1-(betatheta))(1-theta)/theta; // Coefficient on marginal cost in the Phillips Curve
#omega_a = 1 + alpha*(2-alpha)(sigmaeta - 1); // See note to (25)
#kappa_a = lambda*(phi + (sigma/omega_a)); // Real rigidity; see note to (40)
#BigTheta_a = sigma*(1-omega_a)/(sigma + phi*omega_a); // note to (39)
#BigPhi_a = (1-alpha)/omega_a; // (27)

// Monetary policy in the World economy
#phi_a_os = -(sigma*(1+phi)(1-rho_a_os)) / (phi+sigma); // See (51) and the discussion there
#phi_ppi_os = 1.01;
#BigGamma_a = omega_a
(1+phi)/(sigma+phi*omega_a); // Bottom of p.13

// Note: in Monacelli’s Gauss code, “q” stands for the Terms o’ Trade, whereas
// in the NBER paper it stands for the Real Exchange Rate. I’ve followed the NBER paper.

y_os = y_os(+1) - (r_os - ppi_os(+1))/sigma; // Foreign’s Euler eqn, log-deviation form of (22)

mc_os = (sigma + phi)*y_os - (1+phi)*a_os; // Foreign’s marginal cost, log-deviation form of (32)

ppi_os = betappi_os(+1) + lambdamc_os; // Foreign’s Phillips curve (31)

r_os = phi_ppi_osppi_os(+1) + phi_a_osa_os; // Foreign’s Taylor rule — (51) and see also n. 19;
// equivalently, you can specify “ppi_os=0;”.
a_os = rho_a_os*a_os(-1) + eps_a_os; // Foreign’s technology process

a = rho_aa(-1) + eps_a + a_shock_correleps_a_os; // Home’s technology process

ygap = ygap(+1) - (omega_a/sigma)*(r - ppi_h(+1) - rnat); // Home’s IS curve (41)

ppi_h = betappi_h(+1) + kappa_aygap; // Home’s Phillips curve (40)

rnat = -((sigma*(1+phi)(1-rho_a))/(sigma + phiomega_a))a - phiBigTheta_a*(y_os(+1) - y_os);
// Home’s Wicksellian interest rate (41)

//Home’s monetary policy; comment out all but one of these:

	r = 0.5*r(-1) + 1.5*ppi + 0.2*ygap + 0.2*e; 

yflex = BigGamma_aa + BigTheta_ay_os; // Home’s flexprice output deviation (39)

y = yflex + ygap; // Definition of Home output (p. 13)

y = y_os + (omega_a/sigma)*s; // Market clearing (25)

ppi = ppi_h + alpha*(s - s(-1)); // Home CPI inflation (11)

q = (1-alpha)*s; // Real exchange rate (13)

s - s(-1) = e - e(-1) + ppi_os - ppi_h; // Differenced version of (12)

p_h = p_h(-1) + ppi_h; // An identity to pin down the relative price of home goods

cpi_level = cpi_level(-1) + ppi; // " " " " " " consumer price level

y_obs = y;

e_obs = e;

end;

steady;
check;

shocks;
var eps_a; stderr 1;
var eps_a_os; stderr 2;
end;

estimated_params;
stderr eps_a_os, inv_gamma_pdf,1.08, 10;
stderr eps_a, inv_gamma_pdf, 2.08, 10;
epsilon, normal_pdf, 6.02, 0.5;
rho_a, beta_pdf, 0.9, 0.1;
a_shock_correl, beta_pdf, 0.77, 0.1;
end;

varobs y_obs e_obs;
estimation(datafile = simuldataGali2, xls_sheet = Dynare, xls_range =B2:C82, nobs=80, mode_compute=6, mode_check, mh_replic=2000);
gali_monacelliEst2.mod (3.73 KB)
simuldataGali2.xls (60.5 KB)

Your model has two unit roots. You need to use the

option of the estimation command.

it works. Thank you

Hi,
I’m facing the same problem ( Matrix is singular, close to singular or badly scaled), but even trying these suggestions didn’t work. What could be wrong? There are any other solution?

Best, Márcio
dados_tese.xls (25 KB)
median_values.txt (507 Bytes)
estim_jmAb.mod (28.1 KB)

Your data seems to have a seasonal pattern, it seems you don’t have correct observation equations, and you are neglecting parameter dependencies. Please read Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”

Dear sir,

i am adding some shocks and equations to the original file. however, the results seem weird.

1、the standard deviation of exogenous shock se_eps_a_os, se_eps_a, se_eps_r, se_eps_y_os do not take effect, they are almost 0. see figure attached.

2、variable y_ex_obs(red line) does not converge to the original data(black line). see figure attached.

I do not know why and need your help.

Thanks

Jenny
figure.pdf (45.9 KB)
simuldataGali2.xls (68 KB)
gali_monacelliEst5.mod (4.75 KB)

Your data still seem to have a seasonal pattern.

I have commented out some newly added shocks and equations. I processed the data to eliminate the seasonal effect by moving average and then HP detrended. But the shocks still look like a pulse, the standard deviations of exogenous shock se_eps_a_os, se_eps_a are almost 0.

Need your help to find the problem.

Thanks

Jenny
simuldataGali6.xls (58.5 KB)
gali_monacelliEst6.mod (4.82 KB)

This is not a correct way to deal with seasonal patterns. Moreover, what is your e_obs that you match to the non-stationary e in the model? It seems you have a scaling by 100 issue, see [Scaling of Bayesian impulse responses)

e_obs is the observed exchange rate of RMB to dollar. To get the quarterly data, i average the daily exchange rate during the quarter and then take log and HP detrended it. Besides, for real gdp data, i take log and then using moving average to eliminate the seasonal pattern and then HP detrended it. Could you pls. tell me what is the right way to eliminate the seasonal pattern of GDP?

Thanks

For seasonal adjustment use either X11 or Tramo/Seats. Also, do not use the HP filter. See Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”

i use X11 to do seasonal adjust ment and then first difference to eliminate the trend. it seems that the eps_a shock improves a bit. But eps_a_os and eps_r shock not.
simuldataGali6.xls (69 KB)
gali_monacelliEst6.mod (4.94 KB)

Please think about what you are doing before mechanically trying things.

  1. If you have data in first differences, the observation equation needs to reflect this. See
  2. Also, your output data has an endpoint problem. The last two observations are gigantic for some reason.
  3. Why is your prior mean for the shock processes 1, i.e. 100 percent? A one standard deviation shock would then increase the observed series from e.g. 0 to 1. But the data has at most value of about 0.2. See “Remark 10 (Scaling With a Factor 100)” in Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”
  4. Given your observables, eps_a_os is not identified. See the flat line for the likelihood in the mode_check plot.

thank you for your reply. this is the first time i am trying dynare. i am actually learning by doing.

1、i modify the observation equation by letting y_obs = y - y(-1). I wonder if i am using hp filter to detrend, how should i modify the observation equation?
2、i have deleted the last two observations.
3、now i understand remark 10. i changed the mean and std. for the shock process.
4、how can i solve the nonidentification problem? i don’t know how to read mode-check plot?

After making these changes, i found figure 8, the smoothed estimated shocks (eps_a_os and eps_r ) is not centered around zero, how can i solve this problems?
simuldataGali6.xls (58.5 KB)
gali_monacelliEst6.mod (4.95 KB)
figure8.pdf (4.9 KB)

  1. You need to demean the growth rates in the Excel file. Also, do not add mean and stdev at the end. Dynare will take them to be data points.
  2. The only identification problem left is the one for epsilon. You try to estimate it, but epsilon does not show up at all in the model.

For future reference, a replication file for the Gali/Monacelli (2005): Monetary Policy and Exchange Rate Volatility in a Small Open Economy", Review of Economic Studies 72, pp. 707-734 is available at github.com/JohannesPfeifer/DSGE_mod