Estimation: Problems whith reading the data from Excel


I’m trying to estimate a model (Comin & Gertler, Medium Term Business Cycles). But I always get the following error message:

?[size=85]?? Error using ==> cell.strmatch at 18
Requires character array or cell array of strings as inputs.

Error in ==> read_variables at 64
iv = strmatch(var_names_01(dyn_i_01,:),raw(1,:),‘exact’);

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 ==> mf_1_quart at 693

Error in ==> dynare at 102
evalin(‘base’,fname) ;[/size]

I know that the error must be in the reading procedure as I looked around here in the forum. And the charts of the priors already show up.But I can’t find my mistake. As an attachment you find my mod file and the excel file with the data.
I hope somebody can help me?!
Thanks a lot!
usq_cg.xls (37.5 KB)
mf_1_quart.mod (11.8 KB)

Hi there,

I think that there are some bugs in the code of the function read_variables.m in the version 4.0.4.

First, you need to change the mod file. In the estimation set xls_range= a1:d232. The matlab build in function xlsread will automatically separate numbers from the variable names.

Next, click on the in the error message read_variables at 64. Matlab will open the file read_variables near the end of the file. Here you replace the original text be the following:

file_name_02 = [file_name_01 '.xls']; **[num,txt] = xlsread(file_name_01,xls_sheet,xls_range);** for dyn_i_01=1:var_size_01 **iv = strmatch(deblank(var_names_01(dyn_i_01,:)),txt,'exact'); dyn_tmp_01 = [num(1:end,iv)]';** if length(dyn_tmp_01) > dyn_size_01 & dyn_size_01 > 0 error('data size is too large') end dyn_data_01(:,dyn_i_01) = dyn_tmp_01; end

After this modification, I was able to run the file as far as to the error message:

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

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

Error in ==> random_walk_metropolis_hastings at 43
ix2, ilogpo2, ModelName, MhDirectoryName, fblck, fline, npar, nblck,
nruns, NewFile, MAX_nruns, d ] = …

Error in ==> dynare_estimation_1 at 942

Error in ==> dynare_estimation at 62

Error in ==> mf_1_quart at 694

Error in ==> dynare at 102
evalin(‘base’,fname) ;[/code]

Good luck!

Not particularly timely, but I recently got a similar error and was slightly misled by the answer above…

For possible reference: I think the real reason this didn’t work is because the first line of the data section in the excel file needs to contain the variable names. Which it did not in the example files attached. So, another way to get this to work is to modify the .xls file as follows
usq_cg.xls (44 KB)
(and possibly the mod file accordingly).