Dynare Estimation: help

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Dynare Estimation: help

Postby tjenny88 » Thu Apr 16, 2015 8:22 am

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 425 times
Attachments
001 gali 2005.pdf
PAPER
(709.13 KiB) Downloaded 164 times
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Re: Dynare Estimation: help

Postby jpfeifer » Thu Apr 16, 2015 2:23 pm

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Dynare Estimation: help

Postby tjenny88 » Fri Apr 17, 2015 5:55 am

Thank you for your help. I will preprocess data and run the program again.
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Re: Dynare Estimation: help

Postby tjenny88 » Mon May 04, 2015 8:07 am

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);
Attachments
gali_monacelliEst2.mod
program
(3.73 KiB) Downloaded 103 times
simuldataGali2.xls
data
(60.5 KiB) Downloaded 340 times
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Re: Dynare Estimation: help

Postby jpfeifer » Thu May 07, 2015 9:47 am

Your model has two unit roots. You need to use the
Code: Select all
diffuse_filter

option of the estimation command.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Dynare Estimation: help

Postby tjenny88 » Fri May 08, 2015 12:46 am

it works. Thank you
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Re: Dynare Estimation: help

Postby marcio_fr » Tue May 12, 2015 12:07 am

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
Attachments
dados_tese.xls
(25 KiB) Downloaded 303 times
median_values.txt
(507 Bytes) Downloaded 105 times
estim_jmAb.mod
(28.11 KiB) Downloaded 170 times
marcio_fr
 
Posts: 22
Joined: Fri Nov 27, 2009 7:14 pm

Re: Dynare Estimation: help

Postby jpfeifer » Sun May 17, 2015 5:02 pm

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Dynare Estimation: help

Postby tjenny88 » Sun May 24, 2015 1:37 pm

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
Attachments
figure.pdf
(45.87 KiB) Downloaded 118 times
simuldataGali2.xls
(68 KiB) Downloaded 431 times
gali_monacelliEst5.mod
(4.75 KiB) Downloaded 88 times
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Re: Dynare Estimation: help

Postby jpfeifer » Tue May 26, 2015 5:56 pm

Your data still seem to have a seasonal pattern.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Dynare Estimation: help

Postby tjenny88 » Wed May 27, 2015 4:58 pm

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
Attachments
simuldataGali6.xls
(58.5 KiB) Downloaded 144 times
gali_monacelliEst6.mod
(4.82 KiB) Downloaded 101 times
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Re: Dynare Estimation: help

Postby jpfeifer » Wed May 27, 2015 5:21 pm

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Dynare Estimation: help

Postby tjenny88 » Thu May 28, 2015 2:51 pm

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
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Re: Dynare Estimation: help

Postby jpfeifer » Fri May 29, 2015 3:01 pm

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Dynare Estimation: help

Postby tjenny88 » Sun May 31, 2015 2:56 am

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.
Attachments
simuldataGali6.xls
(69 KiB) Downloaded 312 times
gali_monacelliEst6.mod
(4.94 KiB) Downloaded 98 times
tjenny88
 
Posts: 13
Joined: Thu Apr 16, 2015 7:37 am

Next

Return to Dynare help

Who is online

Users browsing this forum: No registered users and 4 guests

cron