Simple model. Unkown error!!

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.

Simple model. Unkown error!!

Postby colenso » Sat Mar 06, 2010 8:52 am

Dear all,
I'm trying to simulate this very simple model with the new version of Dynare, but I'm getting an error message about some ";" being misplaced which I cannot seem to understand. Any thoughts would be much appreciated! Thanks in advance.

d
Attachments
pset4sim.mod
(2.52 KiB) Downloaded 398 times
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Re: Simple model. Unkown error!!

Postby jpfeifer » Sat Mar 06, 2010 12:28 pm

In line 45, there is a wrong bracket:

eta_bar = ((1-theta)*(1-n_bar)*(k_bar/n_bar)^theta/c_bar;


should be

eta_bar = (1-theta)*(1-n_bar)*(k_bar/n_bar)^theta/c_bar;


or something like that. Moreover, you are missing one equation as there are 6 equations but 7 endogenous variables.
------------
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: Simple model. Unkown error!!

Postby colenso » Sat Mar 06, 2010 9:22 pm

Many thanks! I've corrected those errors and simulated the model successfully. However, when I tried to estimate the tested model via ML, it again tells me there is something missing. Perhaps I'm defining the ML estimation in the wrong way? Again, any comment/s will be much appreciated.
Cheers,
d
Attachments
pset4est.mod
Estimated Model
(3.63 KiB) Downloaded 587 times
pset4sim.mod
Simulated model
(2.58 KiB) Downloaded 293 times
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Re: Simple model. Unkown error!!

Postby jpfeifer » Sun Mar 07, 2010 12:02 pm

Dear d,

please be more specific with your error. What does Dynare say. Moreover, you did not post the data-file used for the estimation. From what I can see, the problem is that you do not specify data from Excel-files with the command
Code: Select all
datafile=DataSet.xls

If you look into the Dynare manual at page 35, it says that the command is
Code: Select all
xls_sheet=DataSet

Usually, Dynare does not use the file extension in its commands, so using the ending .xls produces you the preprocessing error

Code: Select all
ERROR: pset4est.mod:118.28: syntax error, unexpected $undefined, expecting COMMA or ')'
------------
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: Simple model. Unkown error!!

Postby colenso » Sun Mar 07, 2010 10:00 pm

Thanks again jpfeifer for your response. Based on your suggestion, I've changed that line in the mode file code. However, I'm now getting two error messages:

(1) If I have the "steady" and "check" commands on, the error is:

STEADY: numerical initial values incompatible with the following equations
4 5 6
??? Error using ==> dynare_solve at 82
exiting ...
Error in ==> steady_ at 124
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...

This is strange because (following the manual's suggestion) I've simulated the model before attempting to estimate it and Dynare can find the steady state without any issues. Moreover, as an initial guess for the estimated parameters I'm using the same values I've used in the simulation of the model (you can still see them commented out in the mode file) so I'm thinking that should not be the problem.

(2) If I comment them out, the error becomes:
??? Reference to non-existent field 'datafile'.

Error in ==> dynare_estimation_1 at 228
if isempty(options_.datafile)

Error in ==> dynare_estimation at 62
dynare_estimation_1(var_list,varargin{:});

Error in ==> pset4est2 at 193
dynare_estimation(var_list_);

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

Do you have any thoughts that could help me? I'm attaching the file I'm using.
Also, do you know of any ML estimation example? Most things I've seen online are Bayesian and the manual does not have a detailed ML example.
Again, many thanks!

d
Attachments
pset4est2.mod
Files used for estimation.
(3.29 KiB) Downloaded 289 times
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Re: Simple model. Unkown error!!

Postby jpfeifer » Mon Mar 08, 2010 9:15 am

The steady state error goes away if you uncomment lines 31-33.

Regarding the second error: the Dynare manual says:

datafile = FILENAME The datafile (a .m file, a .mat file or a .xls file)
xls_sheet = NAME The name of the sheet with the data in an Excel file
xls_range = RANGE The range with the data in an Excel file


So the estimation command should look like:

Code: Select all
estimation(datafile=DataSet,xls_sheet=Table1,xls_range= ...)


In contrast to what I said before, you need to specify the datafile name without the ending in the datafile command. Then the xls_sheet option tells Dynare which sheet to use inside the Excel-file (usually something like Table 1). Moreover, you also need to specify the range in inside the Excel-data sheet that contains the data. Dynare internally uses the xlsread function of Matlab, so you can use the Matlab help to find out more about the syntax of that function. You most probably specify the range with something like

A1:C82

as you have three variables with 81 observations (start at 51 and use 30) and the first line in the Excel-sheet has to contain the variable names as specified in the varobs command of Dynare.
------------
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: Simple model. Unkown error!!

Postby colenso » Tue Mar 09, 2010 7:55 am

Again, thanks for your reply! A few follow up comments/questions:

1) I understand that if I uncomment lines 31-33 the SS problem will disappear but, if I'm trying to estimate the value of those parameters that max the likelihood then my understanding is that I should not be fixing those parameters to some scalar. Perhaps I'm confused as to how Dynare works, but what I thought had to be done was: first defining the parameters at the beginning of the mod file and second give Dynare an initial guess for the estimation. In this opportunity I used an initial guess equal to the value I used when I simulated the model (i.e.: a value for which I know there is a steady state). Is this procedure/way of reasoning incorrect?

2) If I comment out the "steady" and 'check" options I still get an error message in that for some reason I'm not able to get Dynare to recognize the data being imported for the estimation. I've tried with an Excel file as you suggested and I've also tried with a mat file I created. I believe I've followed the steps described in the manual, in that the first row of every column takes the name of the variable. Moreover, I was also able to import the data with Matlab's xlsread command, but I just cannot get Dynare to do it.
Below I copy the error message obtained. I also attach the mod, txt and Excel files (mat files are not allowed) I'm using to this post.

??? Error using ==> eval
Undefined function or variable 'n'.

Error in ==> read_variables at 52
dyn_tmp_01 = eval(var_names_01(dyn_i_01,:));

Error in ==> dynare_estimation_1 at 237
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);

Error in ==> dynare_estimation at 62
dynare_estimation_1(var_list,varargin{:});

Error in ==> pset4est2 at 195
dynare_estimation(var_list_);

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

I appreciate any comment or suggestion you might have. Also, if you know of any working ML estimation example I could take a look to, I believe that would be extremely helpful.
Again, many thanks for all your help!

d
Attachments
DataSet.txt
txt version of the data file
(7.12 KiB) Downloaded 250 times
DataSet.xls
(29.5 KiB) Downloaded 323 times
pset4est2.mod
(3.33 KiB) Downloaded 292 times
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Re: Simple model. Unkown error!!

Postby jpfeifer » Tue Mar 09, 2010 9:14 am

There are several things:

    1.
The initial parameters that give you an error when commented out are not used for the estimation, but for solving the model. That's why you get an error in "dynare_solve" and not in "dynare_estimation". Later on, Dynare uses the initial values supplied in the "estimated_params"-block for "estimation"-command, but that is after the first solution of the model. Hence, you should not comment out these parameters. They do not affect your estimation.
    2.
Never name your file "DataSet" as this is the name of a Matlab-function! Hence, there exists a file named DataSet.m, which obviously does not contain a variable named n. I just renamed the file to datasetabc and now Dynare recognizes that there exists no .m-file with the same name and then uses the Excel-file.
    3.
The Excel-Sheet inside your Excel-file was also named "DataSet", but you told Dynare it was called "Sheet1". I changed the name in the Excel-file to Sheet1 to avoid name-clashes.
    4.
The range specified was inconsistent with the number of observations. You have 251 observations in your Excel-file (range B1:E252), but told Dynare that there are 54+199=253.
    5.
You are doing plain maximum-likelihood estimation, not a Bayesian estimation. So you should not specify the parameters for the MCMC-algorithm in the estimation command like "mh_scale".
    6.
I merged to estimated "estimated_params" and "estimated_params_bounds" blocks in the "estimated_params" according to the Dynare manual. That simplifies the code. The first number after the parameter name gives you the inital value. After this follow the lower and upper bounds.

With the attached files, Dynare at least gives you output, although I do not know your model and do not know if the results make sense. In any case, all estimated parameters seem to hit their upper bounds. This clearly hints at some remaining problems.
Attachments
pset4est3.mod
Changed .mod-file
(3.14 KiB) Downloaded 331 times
datasetabc.xls
Renamed data-set
(34.5 KiB) Downloaded 321 times
------------
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: Simple model. Unkown error!!

Postby colenso » Thu Mar 11, 2010 9:21 am

Thank you so much for your suggestions!

I agree with you that the fact that all estimated parameters seem to hit their upper bounds seems fishy. The model is a VERY simple RBC with government spending and a preference shock, so estimating this should be pretty straight forward. However, for the last 24 hours I've been trying to spot the mistake and cannot seem to find anything wrong with FOCs or the Dynare code itself.
Right now I've ran out of ideas of what could possible be failing in the estimation. Not sure if you have any thoughts, but just in case I've attached the pdf that describes the model and contains the equations that appear numbered in my mod file. As always, any thoughts/suggestions would be much appreciated!

Cheers,

d
Attachments
pset4.xls
(29.5 KiB) Downloaded 279 times
pset4est3.mod
(3.69 KiB) Downloaded 256 times
Pset4.pdf
(91.6 KiB) Downloaded 327 times
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Re: Simple model. Unkown error!!

Postby jpfeifer » Fri Mar 12, 2010 7:08 am

Hi,
your problem is almost surely with the data. Your model is written down in stationary form for a representative agent. However, your data clearly contains a trend in both population and GDP. I guess,you would have to normalize all variables to per capita values. Moreover, you do not allow for a unit root in technology in your model, but only for a temporary technology shock. But the trend in GDP shows that there is such a permanent technology shock. Thus, you have to detrend GDP and consumption, for example by using first differences or a HP filter. As your model seems log-linearized, you also have to take the logarithm of you per capita variables before taking first differences. Use the log for labor, but do not take the first difference. Then define an observation equation in Dynare (and don't forget to rename the variables in the Excel files). For how such an equation looks like, compare Smets/Wouters (2007) in the AER.
------------
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: Simple model. Unkown error!!

Postby colenso » Sat Mar 13, 2010 9:43 pm

Thanks again for your response! You were correct in that the problem was with the data. I've now taken logs, first differences and also de-meaned the data. All this has significantly improved the results.
However, I'm still getting somewhat odd estimates: two are almost hitting their upper bounds, while the remaining one is alarmingly low. I'm guessing the problem must still be with the data and wondered if perhaps you had another suggestion at this point. Again, many thanks for all your help.

d

-------------------------------------

Fval obtained by the minimization routine: -2054.055178

RESULTS FROM MAXIMUM LIKELIHOOD
parameters
Estimate s.d. t-stat

rhoeta 0.9977 0.0000 4063788.5273
rhoG 0.9930 0.0015 680.1308
rhoz 0.4269 0.0619 6.8994
standard deviation of shocks
Estimate s.d. t-stat

ez 0.0134 0.0006 22.2627
eg 0.0290 0.0015 19.8319
eeta 0.1115 0.0050 22.3668
Attachments
pset4est4.mod
(3.67 KiB) Downloaded 289 times
pset4.xls
(33.5 KiB) Downloaded 307 times
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Re: Simple model. Unkown error!!

Postby jpfeifer » Sun Mar 14, 2010 3:56 pm

The problem is that you still did not define an observation equation. Currently you are matching demeaned log-differences in the data with simple log deviations in the model, which cannot work. You need to define an auxiliary variable like

Code: Select all
yobs=y-y(-1);


Your observed variable is then yobs, not y. This is the same procedure as in Smets/Wouters (2007).
------------
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: Simple model. Unkown error!!

Postby colenso » Sun Mar 14, 2010 7:00 pm

Hi and thanks again for your response. I've followed your suggestion of including a measurement equation, yet I still think there is something missing.
I've ran the estimation in log-differences and got:

parameters Estimate s.d. t-stat
rhoeta 0.9950 0.0038 259.7960
rhoG 0.9999 0.0000 3519342.8726
rhoz 0.9998 0.0000 3519342.8498

standard deviation of shocks
Estimate s.d. t-stat
ez 0.0175 0.0008 22.2980
eg 0.0247 0.0011 22.0299
eeta 0.1189 0.0054 22.0332

Next, as a test, decided to run the estimation with demeaned and detrended data to obtain:

parameters Estimate s.d. t-stat
rhoeta 0.9985 0.0000 3519346.9005
rhoG 0.4855 0.0000 0.0000
rhoz 0.9985 0.0000 3519346.6672
standard deviation of shocks

Estimate s.d. t-stat
ez 0.0174 0.0000 0.0000
eg 0.2000 0.0000 0.0000
eeta 0.1170 0.0052 22.3720

None of the above results seem right to me. The model seems to have been correctly imputed into Dynare, so I still believe the answer probably lies in the way the data is being matched. Do you think there is anything that could be done to improve these results? Any thoughts would be much welcomed. Again, many thanks!

Cheers,

d
Attachments
pset4 (detrended only).xls
Detrended only data set
(33.5 KiB) Downloaded 330 times
pset4.xls
Demeaned and detrended data set
(33.5 KiB) Downloaded 344 times
pset4est5.mod
Model with measurement equation
(3.75 KiB) Downloaded 401 times
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Re: Simple model. Unkown error!!

Postby jpfeifer » Mon Mar 15, 2010 7:19 am

The definition of the observed variables has to match the data you give to Dynare. So you obviously need to define a measurement equation for each (!) variable, not only for y (just as specified in the reference I gave you several times). Matching demeaned log differences in the data to the first difference of loglinearized model variables makes sure that the different steady state values of your model and the empirical data do not matter. The reason is that the steady state values cancel out by taking the difference of log deviations from steady state.

Code: Select all
yobs=log(Y/Y(-1))=log(Y/Y(-1)*Y_SS/Y_SS)= log(Y/Y_SS)-log(Y(-1)/Y_SS)=y-y(-1);


which is your observation equation for y. The one for c follows correspondingly. The reason for demeaning the log-differences is that your model variables are made stationary by detrending. Hence, there should be no steady state growth.
That leaves you with a problem for n, where you usually do not take log differences in the data but the simple log. As in the model hours are normalized to be between 0 and 1, which is not the case in the data, you have to specify a measurement equation like

Code: Select all
nobs= -log(n_SS) + n;


where n_SS is the steady state value from the model. This is because the log deviations from the model are simply n=log(Nobs/N_SS), but you in the data you have
Code: Select all
nobs =log(Nobs)=log(Nobs*N_SS/N_SS)=n + log(N_SS).

From this, the above equation directly follows.

But you could try to just take demeaned log-differences for all variables and specify the same measurement equation for n as for c and y. Although this is not the standard in the literature (again see Smets/Wouters (2007)), it should also work.
------------
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: Simple model. Unkown error!!

Postby colenso » Tue Mar 16, 2010 6:56 pm

Thank you so much for all your help! It seems to be working fine now.
Again, I'm very grateful for you advice and suggestions.

Cheers,

d
colenso
 
Posts: 14
Joined: Tue Mar 17, 2009 4:13 am

Next

Return to Dynare help

Who is online

Users browsing this forum: No registered users and 9 guests