Page 1 of 1

Bayesian Estimation not reading data file

PostPosted: Thu Nov 13, 2014 2:54 pm
by Nice
Hello,

I am new to using Bayesian estimation techniques and this is my first attempt at estimating with Dynare. It seems that in the estimation command Dynare is not reading the data file. I get the following error whether I try to perform the estimation using Dynare 4.3 or the latest version so I am not sure. I have made sure that the variables in the data file are the same as in varobs

I get the following error

ERROR: The estimation statement requires a data file to be supplied via the datafile option.

Error using dynare (line 114)
DYNARE: preprocessing failed
>> dynare leeper_closed_est.mod

I have attached the files. Any help would be appreciated.

Re: Bayesian Estimation not reading data file

PostPosted: Thu Nov 13, 2014 4:39 pm
by Nice
Additionally, I have tried to load the file as a .mat file AND .xls and it does not work either. For some reason it cannot match or recognize the observable variables in the data file.

I get the following error message:

You did not declare endogenous variables after the estimation/calib_smoother command.
Loading 193 observations from data.mat

Index exceeds matrix dimensions.
Error in initialize_dataset (line 58)
rawdata = rawdata(first:(first+dataset_.info.ntobs-1),:);
Error in dynare_estimation_init (line 322)
dataset_ =
initialize_dataset(options_.datafile,options_.varobs,options_.first_obs,options_.nobs,transformation,options_.prefilter,xls);
Error in dynare_estimation_1 (line 59)
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_] =
dynare_estimation_init(var_list_, dname, [], M_, options_, oo_,
estim_params_, bayestopt_);
Error in dynare_estimation (line 70)
dynare_estimation_1(var_list,dname);
Error in leeper_closed_est (line 503)
dynare_estimation(var_list_);
Error in dynare (line 120)
evalin('base',fname) ;
>>
when I ask dynare to read the file as a .xls file I get the following error:

You did not declare endogenous variables after the estimation/calib_smoother command.
Error using cell/strmatch (line 20)
Requires character array or cell array of strings as inputs.
Error in read_variables (line 74)
iv = strmatch(var_names_01(dyn_i_01,:),raw(1,:),'exact');
Error in initialize_dataset (line 31)
rawdata = read_variables(datafile,varobs,[],xls.sheet,xls.range);
Error in dynare_estimation_init (line 322)
dataset_ =
initialize_dataset(options_.datafile,options_.varobs,options_.first_obs,options_.nobs,transformation,options_.prefilter,xls);
Error in dynare_estimation_1 (line 59)
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_] =
dynare_estimation_init(var_list_, dname, [], M_, options_, oo_,
estim_params_, bayestopt_);
Error in dynare_estimation (line 70)
dynare_estimation_1(var_list,dname);
Error in leeper_closed_est (line 503)
dynare_estimation(var_list_);
Error in dynare (line 120)
evalin('base',fname) ;

Thanks
>>

Re: Bayesian Estimation not reading data file

PostPosted: Thu Nov 13, 2014 5:02 pm
by jcsantanac
Hi !

i'm not expert in dynare but i had same problems in the past. Is possible that you need use the argument "xls sheet" or "xls range" in the estimation function to reference the range of data or a sheet inside the xls book. Put your xls file in the directory where you have your *.mod code and use one or both arguments that i said you before. For example, i use "estimation(xls sheet=data, xls_range=B1G70,.." I hope works it!

Re: Bayesian Estimation not reading data file

PostPosted: Thu Nov 13, 2014 5:25 pm
by Nice
HI,

Thank you for your suggestion I tried the following command

estimation(xls_sheet=data,xls_range=A1:J194,nobs=193, first_obs= 500, mh_replic=2000, mh_nblocks=2, mh_drop=0.45, mh_jscale=0.8, mode_compute=4);

but again I get the following error:

ERROR: The estimation statement requires a data file to be supplied via the datafile option.

Error using dynare (line 114)
DYNARE: preprocessing failed
>>

Re: Bayesian Estimation not reading data file

PostPosted: Thu Nov 13, 2014 7:15 pm
by jcsantanac
Hi,

Try this one: estimation(datafile=data,xls_sheet=,name_sheet_data_reference_in_xlsbook,xls_range=A1J194,...)

datafile = FILENAME The datafile: a .m file, a .mat file, a .csv file, or a .xls/.xlsx file (under Octave,
the io from Octave-Forge is required for the .csv, .xls and .xlsx formats; in
addition, for the .xls and .xlsx formats, the java package is required, along with
a Java Runtime Environment)

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




Nice wrote:HI,

Thank you for your suggestion I tried the following command

estimation(xls_sheet=data,xls_range=A1:J194,nobs=193, first_obs= 500, mh_replic=2000, mh_nblocks=2, mh_drop=0.45, mh_jscale=0.8, mode_compute=4);

but again I get the following error:

ERROR: The estimation statement requires a data file to be supplied via the datafile option.

Error using dynare (line 114)
DYNARE: preprocessing failed
>>

Re: Bayesian Estimation not reading data file

PostPosted: Sun Nov 16, 2014 2:48 pm
by jpfeifer
There are a bunch of problems:
  • It should be something along the lines of
    Code: Select all
    estimation(datafile=data,xls_sheet=data, nobs=193, first_obs= 1, mh_replic=2000, mh_nblocks=2, mh_drop=0.45, mh_jscale=0.8, mode_compute=4);


  • first_obs cannot be 500. You only have 193 observations

  • If you estimate parameters like SIGMA_B_H, the corresponding shocks need to have unit variance, but you have no shocks block

  • You are neglecting the dependence of steady state values and parameters on estimated parameters. Estimation results will be wrong. Use model-local variables. 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

  • You should never name your datafile data. It invites problems with a lot of fuctions/variables called dat.

  • Your observation equations mapping data to model variables are completely wrong (non-demeaned data, inconsistent constant values etc.). 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 on how to do this correctly.


Re: Bayesian Estimation not reading data file

PostPosted: Thu Nov 27, 2014 9:49 pm
by Nice
Hello jpfeifer ,

Thank you very much for referring me to your estimation guide, it helped me tremendously.

I have the following questions:

1. Use of model-local variables, for the model I believe that I would only need to declare the following as model local variables
Y_h_bar as it depends on K_h_bar which depends on H, KAPPA and GAMMA
B_h_bar, G_h_bar, and Z_h_bar as they all depend on Y_h_bar

Do I remove these equations from the steady state block and place them in the model block and insert a "#" in front of it while leaving the rest of the steady state equations in place? It is not very clear to me how to treat my steady state block. In the examples with in the guide you always have the steady state block after the model block, but some of my model equations depend on the state state of the variables.

2. Specifying observation equations: I am trying to replicate the estimation of the model in Leeper, Plante and Traum (2010) "Dynamics of Fiscal Financing in the United States" according to their appendix they specify an observable variable as follows:

An observable variable X = ln (x / popindex) * 100

where x is in per capita and popindex = population index

I have written the code in log linearized terms by placing my variables in exp ( ). My data however was just raw data which I have now de-trended and converted into per capta terms by dividing by the population index. My observable variable x_obs = (x/popindex) Remark 17 suggests that Dynare takes logs of the empirical series but is this the case even if I do not use the loglinear command?

So when I am specifying the observation equation in the .mod file is the correct equation

x_obs = exp(x) - log(x_bar) or do I not need to subtract the mean ?

I have attached the .mod file, the data file in .m format as well as the excel version which shows the transformations

Currently I am getting the following error:

Error using chol
Matrix must be positive definite.
Error in metropolis_hastings_initialization (line 65)
d = chol(vv);
Error in random_walk_metropolis_hastings (line 58)
[ ix2, ilogpo2, ModelName, MhDirectoryName, fblck, fline, npar,
nblck, nruns, NewFile, MAX_nruns, d ] = ...
Error in dynare_estimation_1 (line 872)
feval(options_.posterior_sampling_method,objective_function,options_.proposal_distribution,xparam1,invhess,bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
Error in dynare_estimation (line 70)
dynare_estimation_1(var_list,dname);
Error in leeper_closed_est1 (line 535)
dynare_estimation(var_list_);
Error in dynare (line 120)
evalin('base',fname) ;
>>

Re: Bayesian Estimation not reading data file

PostPosted: Tue Dec 02, 2014 9:07 pm
by Nice
I believe I have corrected the errors with respect to model local variables but there is still a problem with specifying obliteration equations. The updated files are attached.

Any help would be greatly appreciated.