I Need Help On DSGE Estimation

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.

I Need Help On DSGE Estimation

Postby dapomi » Mon Jan 05, 2015 6:24 pm

Hello Everyone,

I am Dapomi from the University of Ibadan, Nigeria. I am currently working on 'The of the Interest on Business Cycle in Nigeria'. I am trying to use the DSGE Model using Dynare code on Matlab. However, I am currently try my hand the following code:

var y c k i l y_l w r z;
varexo e;
parameters beta psi delta alpha rho sigma epsilon;

alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
rho = 0.95;
sigma = (0.007/(1-alpha));
epsilon = 10;

model;
(1/c) = beta*(1/c(+1))*(1+r(+1)-delta);
psi*c/(1-l) = w;
c+i = y;
y = (k(-1)^alpha)*(exp(z)*l)^(1-alpha);
w = y*((epsilon-1)/epsilon)*(1-alpha)/l;
r = y*((epsilon-1)/epsilon)*alpha/k(-1);
i = k-(1-delta)*k(-1);
y_l = y/l;
z = rho*z(-1)+e;
end;

initval;
k = 9;
c = 0.76;
l = 0.3;
w = 2.07;
r = 0.03;
z = 0;
e = 0;
end;
steady;
check;

shocks;
var e = sigma^2;
end;

varobs y;

estimated_params;
beta, beta_pdf, 0.99, 0.02;
stderr e, inv_gamma_pdf, 0.01, inf;
end;

estimation(datafile=foreview,mode_compute=0,mode_file=dsgeNine_mode,mh_replic=2000,mh_nblocks=2,mh_drop=0.5,mh_jscale=0.2);

The excel data of the Nigerian GDP I am using for this model is attached with this topic/message.

However, after running the model the following is the result that I am getting with errors in it that I cannot interprete and unable to get my posterior mean:

Configuring Dynare ...
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.4.3).
Starting preprocessing of the model file ...
Found 9 equation(s).
Evaluating expressions...done
Computing static model derivatives:
- order 1
Computing dynamic model derivatives:
- order 1
- order 2
Processing outputs ...done
Preprocessing completed.
Starting MATLAB/Octave computing.


STEADY-STATE RESULTS:

y 0.892084
c 0.707986
k 8.00425
i 0.184098
l 0.302733
y_l 2.94677
w 1.7769
r 0.033101
z 0

EIGENVALUES:
Modulus Real Imaginary

0.9498 0.9498 0
0.95 0.95 0
1.071 1.071 0
Inf Inf 0


There are 2 eigenvalue(s) larger than 1 in modulus
for 2 forward-looking variable(s)

The rank condition is verified.


You did not declare endogenous variables after the estimation/calib_smoother command.


Loading 53 observations from foreview.xlsx

Initial value of the log posterior (or likelihood): -26085.2619

POSTERIOR KERNEL OPTIMIZATION PROBLEM!
(minus) the hessian matrix at the "mode" is not positive definite!
=> posterior variance of the estimated parameters are not positive.
You should try to change the initial values of the parameters using
the estimated_params_init block, or use another optimization routine.
Warning: The results below are most likely wrong!
> In dynare_estimation_1 at 694
In dynare_estimation at 89
In dsgeNine at 178
In dynare at 180

RESULTS FROM POSTERIOR ESTIMATION
parameters
prior mean mode s.d. prior pstdev

beta 0.990 1.0000 0.0000 beta 0.0200

standard deviation of shocks
prior mean mode s.d. prior pstdev

e 0.010 1.5659 0.0000 invg Inf


Log data density [Laplace approximation] is -26098.508064.

??? Error using ==> chol
Matrix must be positive definite.

Error in ==> metropolis_hastings_initialization at 68
d = chol(vv);

Error in ==> random_walk_metropolis_hastings at 62
[ ix2, ilogpo2, ModelName, MetropolisFolder, fblck, fline, npar, nblck, nruns, NewFile,
MAX_nruns, d ] = ...

Error in ==> dynare_estimation_1 at 782
feval(options_.posterior_sampling_method,objective_function,options_.proposal_distribution,xparam1,invhess,bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_);

Error in ==> dynare_estimation at 89
dynare_estimation_1(var_list,dname);

Error in ==> dsgeNine at 178
dynare_estimation(var_list_);

Error in ==> dynare at 180
evalin('base',fname) ;

I will be so glad if you could help on what to do. Besides, I am using Matlab2009. Thanks so much as I await your helpful responses.
NB: This is the data I used

y
514.83
505.40
515.26
547.71
562.66
577.59
541.21
446.16
430.97
523.36
639.40
713.63
720.39
740.91
802.67
740.26
784.23
806.83
737.50
764.19
773.86
654.23
635.90
587.13
544.86
582.59
581.86
562.79
602.42
629.12
663.33
677.39
679.78
677.54
661.49
661.32
672.75
673.86
669.56
660.18
678.59
682.25
675.56
726.45
783.07
804.15
831.79
862.14
889.43
925.79
972.55
1015.56
1052.34

Kind regards,
Dapomi.
dapomi
 
Posts: 6
Joined: Wed Dec 24, 2014 7:11 am

Re: I Need Help On DSGE Estimation

Postby jpfeifer » Mon Jan 05, 2015 10:41 pm

Data and model are not correctly matched. Please read my Guide to Observation Equations posted on my homepage. In a nutshell, use demeaned first differences of your data and then use a corresponding observation equation.
------------
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: I Need Help On DSGE Estimation

Postby dapomi » Fri Jan 09, 2015 8:09 am

But when I used compute_mode=6, the problem was fixed but the number graphs that I am supposed to get is not complete. It remains one to complete. What could have caused that?
dapomi
 
Posts: 6
Joined: Wed Dec 24, 2014 7:11 am

Re: I Need Help On DSGE Estimation

Postby jpfeifer » Fri Jan 09, 2015 11:19 am

Please do as I told you. Your model might run with mode_compute=6, but the results will be wrong.
------------
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: I Need Help On DSGE Estimation

Postby dapomi » Sat Jan 17, 2015 2:54 pm

Good Day Professor,

Please sir, I have tried all my brain could allow me to do on what you asked me to do but I am unable to get it and keep getting errors. In fact, I find it difficult to understand even as much as I tried for days.

Sir, I now seriously need your help as the deadline for the submission of this project is next week Wednesday 21 January, 2015. Please I need your help to assist me in constructing a model that I can use to assess 'the Role of Interest Rate in Nigeria' . I have tried my hands on fs2000n.mod file which I attached and renamed as fs2000ns2.mod below. Another one I tried is the named dsgeFive.mod file attached with this message too.

Besides, the data for the Nigeria interest rate(r), export(x) and GDP(y) are as pasted below. I tried uploading the excel data file but this site rejected it but I still tried renamed the excel file and attached it as a xyz.m file below . I included export in order to know the effect of oil on the business cycle in Nigeria since the oil export constitute more 90% of the Nigerian export.

In conclusion sir, I will so much appreciate it if you could please assist me on this because it means I reached mu limit and no where to run to again. Thank you so much sir as I await your timely response.
Year r x y
1960 0.0 339.4 2233.0
1961 4.0 347.3 2361.2
1962 3.0 337.1 2597.6
1963 3.0 378.7 2755.8
1964 3.5 429.3 2894.4
1965 3.5 536.8 3110.0
1966 3.5 568.2 3374.8
1967 3.5 485.6 2752.6
1968 3.0 422.1 2656.2
1969 3.0 636.0 3549.3
1970 3.0 885.7 5281.1
1971 3.0 1293.4 6650.9
1972 3.0 1434.2 7187.5
1973 3.0 2278.4 8630.5
1974 3.0 5794.8 18823.1
1975 4.0 4925.5 21475.2
1976 4.0 6751.1 26655.8
1977 4.0 7630.7 31520.3
1978 5.0 6064.4 34540.1
1979 5.0 10836.8 41974.7
1980 6.0 14186.7 49632.3
1981 6.0 11023.3 47619.7
1982 7.5 8206.4 49069.3
1983 7.5 7502.5 53107.4
1984 9.5 9088.0 59622.5
1985 9.5 11720.8 67908.6
1986 9.5 8920.6 69147.0
1987 14.0 30360.6 105222.8
1988 14.5 31192.8 139085.3
1989 16.4 57971.2 216797.5
1990 18.8 109886.1 267550.0
1991 14.3 121535.4 312139.7
1992 16.1 205611.7 532613.8
1993 16.7 218770.1 683869.8
1994 13.5 206059.2 899863.2
1995 12.6 950661.4 1933211.6
1996 11.7 1309543.4 2702719.1
1997 4.8 1241662.7 2801972.6
1998 5.5 751856.7 2708430.9
1999 5.3 1188969.8 3194015.0
2000 5.3 1945723.3 4582127.3
2001 5.5 1867953.9 4725086.0
2002 4.2 1744177.7 6912381.3
2003 4.1 3087886.4 8487031.6
2004 4.2 4602781.5 11411066.9
2005 3.8 7246534.8 14572239.1
2006 3.1 7324680.6 18564594.7
2007 3.5 8309758.3 20657317.7
2008 2.8 10161490.1 24296329.3
2009 2.7 8356385.6 24794238.7
2010 2.2 11532022.7 33984754.1
2011 1.4 14231453.4 37543654.7
2012 1.7 14412301.0 40544099.9

r = Interest rate
x = export
y = GDP at current price
Attachments
xyz.m
(10.78 KiB) Downloaded 75 times
fs2000ns2.mod
(2.64 KiB) Downloaded 69 times
dsgeFive.mod
(2.36 KiB) Downloaded 74 times
dapomi
 
Posts: 6
Joined: Wed Dec 24, 2014 7:11 am

Re: I Need Help On DSGE Estimation

Postby jpfeifer » Sat Jan 17, 2015 4:31 pm

See my message two weeks ago. Again your data is in levels. I told you to use demeanded first differences.
------------
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: I Need Help On DSGE Estimation

Postby dapomi » Sat Jan 17, 2015 6:28 pm

Yes sir, I had done what you directed me to do but I am still getting the same error. That was why I attached the two .mod files in my earlier message today.

Please try and help me to review the two .mod files for any mistake(s) and modification(s). Please sir, this is where and the only way I need your help now.

Thank you sir.
dapomi
 
Posts: 6
Joined: Wed Dec 24, 2014 7:11 am

Re: I Need Help On DSGE Estimation

Postby jpfeifer » Sun Jan 18, 2015 3:30 pm

Sorry, but I cannot do the model building for you. If you are unable to add open economy sector features to your closed economy framework, you should not be working on this project in the first place. After the model building, you still need to get estimation running, which is another hard challenge. Given that you have been unable to follow my advice with the first model you posted, I do not see how this project will be successful.
In case this is a project for a university class, tell your teacher that estimation of DSGE models is nothing that students can easily do without being thoroughly prepared. Usually, this means about two years of graduate education.
------------
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: I Need Help On DSGE Estimation

Postby dapomi » Sat Mar 07, 2015 3:09 pm

Please Prof., how can I fix the error of inability to compute the steady state after rewriting the model to include exports, and then having the model and the result look as follows:

var m P c e W R k d n l x gy_obs gr_obs gx_obs Y_obs R_obs X_obs tot y dA;
varexo e_a e_R e_x;
parameters alp bet gam mst rho psi del xsta ysta miu phi stot xdsta;

alp = 0.33;
bet = 0.99;
gam = 0.003;
mst = 1.011;
rho = 0.7;
psi = 0.787;
del = 0.02;
xdsta = 1.66;
xsta = 0.33;
ysta = 1.66;
miu = 0.05;
stot = 1.2;
phi = 0.33;

model;
dA = exp(gam+e_a);
// The stochastic process for interest rate is as below:
R = rho*R(-1)+e_R;
-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
W = l/n;
-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
P*c = m;
m-1+d = l;
e = exp(e_a);
y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
tot = rho*tot(-1)+(1-rho)*tot+e_x;
x = ((1-miu)/miu)^(1/(phi-1))*((xsta+((1-miu)/miu)^(1/(phi-1))*tot^(1/(phi-1))*xdsta))^(-1)*(tot^(1/(phi-1))*xdsta*(y+(1/(phi-1))*tot));
gy_obs = dA*y/y(-1);
gr_obs = (R/R(-1))*dA;
gx_obs = dA*x/x(-1);

Y_obs/Y_obs(-1) = gy_obs;
R_obs/R_obs(-1) = gr_obs;
X_obs/X_obs(-1) = gx_obs;
end;


initval;
k = 6;
m = mst;
P = 2.25;
c = 0.45;
x = xsta;
e = 1;
W = 8.52;
R = 1.01;
d = 0.85;
n = 0.19;
l = 0.86;
tot = 1.02;
y = 1.16;
gy_obs = exp(gam);
gr_obs = exp(-gam);
gx_obs = exp(tot);
dA = exp(gam);
end;

shocks;
var e_a; stderr 0.014;
var e_R; stderr 0.005;
var e_x; stderr 0.011;
end;

steady;
check;

estimated_params;
alp, beta_pdf, 0.356, 0.02;
bet, beta_pdf, 0.993, 0.002;
gam, normal_pdf, 0.0085, 0.003;
mst, normal_pdf, 1.0002, 0.007;
rho, beta_pdf, 0.129, 0.223;
psi, beta_pdf, 0.65, 0.05;
del, beta_pdf, 0.01, 0.005;
stderr e_a, inv_gamma_pdf, 0.035449, inf;
stderr e_R, inv_gamma_pdf, 0.008862, inf;
stderr e_x, inv_gamma_pdf, 0.008850, inf;
end;

varobs R_obs Y_obs X_obs;

observation_trends;
R_obs (-gam);
Y_obs (gam);
X_obs (tot);
end;

options_.unit_root_vars = {'R_obs'; 'Y_obs'; 'X_obs'};
//stoch_simul(order=1,irf=70);
estimation(datafile=arindata,nobs=53,loglinear,mh_replic=2000,mode_compute=6,mh_nblocks=2,mh_drop=0.45,mh_jscale=0.8,diffuse_filter);

THE RESULT WITH ERROR IS:

Configuring Dynare ...
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.4.3).
Starting preprocessing of the model file ...
Substitution of endo leads >= 2: added 1 auxiliary variables and equations.
Found 21 equation(s).
Evaluating expressions...done
Computing static model derivatives:
- order 1
Computing dynamic model derivatives:
- order 1
- order 2
Processing outputs ...done
Preprocessing completed.
Starting MATLAB/Octave computing.


SOLVE: maxit has been reached




Residuals of the static equations:

Equation number 1 : -0.0018025
Equation number 2 : 0.303
Equation number 3 : -0.00090597
Equation number 4 : 3.9937
Equation number 5 : -0.092229
Equation number 6 : 0.45768
Equation number 7 : -0.017824
Equation number 8 : -0.0054823
Equation number 9 : 0.0015
Equation number 10 : 0.001
Equation number 11 : 0
Equation number 12 : 0.5669
Equation number 13 : 0
Equation number 14 : 0.3506
Equation number 15 : -0.0006009
Equation number 16 : -0.0006009
Equation number 17 : -0.0006009
Equation number 18 : -0.00060107
Equation number 19 : -0.00060107
Equation number 20 : -0.00060107


??? Error using ==> print_info at 74
Impossible to find the steady state. Either the model doesn't have a steady state, there
are an infinity of steady states, or the guess values are too far from the solution

Error in ==> steady at 92
print_info(info,options_.noprint, options_);

Error in ==> ui_dsge at 259
steady;

Error in ==> dynare at 180
evalin('base',fname) ;

>> Thanks so much as I await your response sir.
dapomi
 
Posts: 6
Joined: Wed Dec 24, 2014 7:11 am

Re: I Need Help On DSGE Estimation

Postby jpfeifer » Sun Mar 08, 2015 8:59 am

Two things:
1. Try increasing maxit, i.e.
Code: Select all
steady(maxit=1000);

2. Note that the
Code: Select all
observation_trends;

is currently broken. We are working on it, but for the time being, you need to find a workaround (e.g. estimating the model using first differences with a mean growth rate). For updates on this matter, see https://github.com/DynareTeam/dynare/pull/852
------------
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: I Need Help On DSGE Estimation

Postby dapomi » Thu Mar 12, 2015 11:38 am

Prof., I have tried what you asked to do but I'm still getting the same error. My questions now are:

1. What should I do now?
2. How can I calculate the steady state for this model?

Thank you as await your usual timey response sir.
dapomi
 
Posts: 6
Joined: Wed Dec 24, 2014 7:11 am

Re: I Need Help On DSGE Estimation

Postby jpfeifer » Sun Mar 15, 2015 5:15 pm

Try to provide an analytic steady state. For the relatively small model you have, this should be straightforward.
------------
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


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 7 guests