Simple model. Unkown error!

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.

pset4sim.mod (2.52 KB)

In line 45, there is a wrong bracket:

should be

or something like that. Moreover, you are missing one equation as there are 6 equations but 7 endogenous variables.

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.
pset4est.mod (3.63 KB)
pset4sim.mod (2.58 KB)

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

If you look into the Dynare manual at page 35, it says that the command is

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

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

Error in ==> pset4est2 at 193

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!

pset4est2.mod (3.29 KB)

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

Regarding the second error: the Dynare manual says:

[quote]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[/quote]

So the estimation command should look like:

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


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.

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

Error in ==> pset4est2 at 195

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!

DataSet.txt (7.12 KB)
DataSet.xls (29.5 KB)
pset4est2.mod (3.33 KB)

There are several things:

[ul]1. [/ul] 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.
[ul]2. [/ul]
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.
[ul]3. [/ul]
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.
[ul]4. [/ul]
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.
[ul]5. [/ul]
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”.
[ul]6. [/ul]
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.
pset4est3.mod (3.14 KB)
datasetabc.xls (34.5 KB)

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!


pset4.xls (29.5 KB)
pset4est3.mod (3.69 KB)
Pset4.pdf (91.6 KB)

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.

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.


Fval obtained by the minimization routine: -2054.055178

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
pset4est4.mod (3.67 KB)
pset4.xls (33.5 KB)

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

Your observed variable is then yobs, not y. This is the same procedure as in Smets/Wouters (2007).

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!


pset4 (detrended only).xls (33.5 KB)
pset4.xls (33.5 KB)
pset4est5.mod (3.75 KB)

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.

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

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

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.

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.



Hello boys & girls,

I read through this topic and I tried to follow your indications.

The model with which I am playing is in log deviations from its steady state and I have:

  1. de-trended my data(which is quarterly by the way) with the HP filter, Lambda = 1600
  2. taken first order log differences of the de-trended data
  3. de-meaned the first order log differences
    Please see data set attached.

The error message is also attached.
When I run the estimation it basically iterates more than 200 times and afterwards says that there was a posterior optimization problem.

My questions:

  1. is my data set ok? Is the model too big for only 5 observables?
  2. are my measurement equations ok? Lines 460-464;
  3. Next I would like to add more observables like inflation for example. I will consider year-on-year inflation, quarterly data. How would a measurement equation look like? for example obs_inflation = inflation - log(inflation_steady_state)?

Please help a desperate man! Good bless you!
Model_abc.mod (31.9 KB)
FinalDataSet_HP.xls (32.2 KB)
Error msg.pdf (3.72 KB)

My model variables is in deviation from the steady state so I manage my observable variables like this:
1- log transformation
2-Use HP filter to extract the deviation from the steady state
So My observation equation is y observable variable = y of the model. Dont need to make a transformation to match data to the model
am I right?

@Newbie: Please see Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”

@Ravelomanana Do not use the two-sided HP-filter (see the linked document). Apart from that, you are correct. Your data and your model will both be percentage deviations from steady state/the BGP.