Page 1 of 2

Dynare Estimation: help

PostPosted: Thu Apr 16, 2015 8:22 am
by tjenny88
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-(beta*theta))*(1-theta)/theta; // Coefficient on marginal cost in the Phillips Curve
#omega_a = 1 + alpha*(2-alpha)*(sigma*eta - 1); // See note to (25)
#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 = beta*ppi_os(+1) + lambda*mc_os; // Foreign's Phillips curve (31)

r_os = phi_ppi_os*ppi_os(+1) + phi_a_os*a_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_a*a(-1) + eps_a + a_shock_correl*eps_a_os; // Home's technology process

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

ppi_h = beta*ppi_h(+1) + kappa_a*ygap; // Home's Phillips curve (40)

rnat = -((sigma*(1+phi)*(1-rho_a))/(sigma + phi*omega_a))*a - phi*BigTheta_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_a*a + BigTheta_a*y_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
data
(24 KiB) Downloaded 424 times

Re: Dynare Estimation: help

PostPosted: Thu Apr 16, 2015 2:23 pm
by jpfeifer
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" https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.

Re: Dynare Estimation: help

PostPosted: Fri Apr 17, 2015 5:55 am
by tjenny88
Thank you for your help. I will preprocess data and run the program again.

Re: Dynare Estimation: help

PostPosted: Mon May 04, 2015 8:07 am
by tjenny88
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-(beta*theta))*(1-theta)/theta; // Coefficient on marginal cost in the Phillips Curve
#omega_a = 1 + alpha*(2-alpha)*(sigma*eta - 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 = beta*ppi_os(+1) + lambda*mc_os; // Foreign's Phillips curve (31)

r_os = phi_ppi_os*ppi_os(+1) + phi_a_os*a_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_a*a(-1) + eps_a + a_shock_correl*eps_a_os; // Home's technology process

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

ppi_h = beta*ppi_h(+1) + kappa_a*ygap; // Home's Phillips curve (40)

rnat = -((sigma*(1+phi)*(1-rho_a))/(sigma + phi*omega_a))*a - phi*BigTheta_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_a*a + BigTheta_a*y_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);

Re: Dynare Estimation: help

PostPosted: Thu May 07, 2015 9:47 am
by jpfeifer
Your model has two unit roots. You need to use the
Code: Select all
diffuse_filter

option of the estimation command.

Re: Dynare Estimation: help

PostPosted: Fri May 08, 2015 12:46 am
by tjenny88
it works. Thank you

Re: Dynare Estimation: help

PostPosted: Tue May 12, 2015 12:07 am
by marcio_fr
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

Re: Dynare Estimation: help

PostPosted: Sun May 17, 2015 5:02 pm
by jpfeifer
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" https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.

Re: Dynare Estimation: help

PostPosted: Sun May 24, 2015 1:37 pm
by tjenny88
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

Re: Dynare Estimation: help

PostPosted: Tue May 26, 2015 5:56 pm
by jpfeifer
Your data still seem to have a seasonal pattern.

Re: Dynare Estimation: help

PostPosted: Wed May 27, 2015 4:58 pm
by tjenny88
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

Re: Dynare Estimation: help

PostPosted: Wed May 27, 2015 5:21 pm
by jpfeifer
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 http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=5491

Re: Dynare Estimation: help

PostPosted: Thu May 28, 2015 2:51 pm
by tjenny88
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

Re: Dynare Estimation: help

PostPosted: Fri May 29, 2015 3:01 pm
by jpfeifer
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" https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf

Re: Dynare Estimation: help

PostPosted: Sun May 31, 2015 2:56 am
by tjenny88
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.