I want to estimate (ML estimation) a model using Dynare. There are 6 variables in the model, and I have 1,000 artificial data for each variable for 200 periods. Therefore, every variable is esentially a 200 by 1,000 matrix. However, I tried many times and cannot get Dynare to work properly. I wrote the code as the following:
@#for i in 1:1000
estimation(datafile=mydata@{y1(:,i),c1(:,i),pi1(:,i),r1(:,i),g1(:,i),z1(:,i)},nograph);
@#endfor
y1, c1, pi1,r1, g1 and z1 are 6 variables. The error message says: “unknown variable: y1”, but I declare all the variables before doing estimation. I would like to know how I should fix my errors. Thanks for your help.
load gapfirst;
for i=1:1000
my2=[y1(:,i),c1(:,i),pi1(:,i),r1(:,i),g1(:,i),z1(:,i)];
save my3.mat my2;
estimation(datafile=my3,nograph);
end
“gapfirst” is my original data file. However, this still cannot work. The error message is:
??? Reference to non-existent field ‘y1’.
I think the problem is: now the variable is my2 in my3.mat, but the estimation process requires y1, c1, pi1, r1, g1 and z1. I try to add something like y1=my2(:,1) in the loop, but dynare does not accept the colon (:). Thus I think my problem is: how to make the variable my2 become y1, c1, pi1, r1, g1 and z1 in a way that is readable for dynare. Any help will be deeply appreciated.
Ok I understand the problem. The point is that the MAT-file created must constain variables with the same names than the variables estimated by Dynare (those declared by the “varobs” statement). I had forgotten that point.
With the example that you’ve just posted, you can try:
load gaponetry;
for i=1:1000
y = y1(:,i);
pi = pi1(:,i);
r = r1(:,i);
g = g1(:,i);
z = z1(:,i);
save mydata.mat y pi r g z;
estimation(datafile=mydata,nograph);
end
Thanks for your kind help. Unfortunately, your code still does not work. The error message is:
Starting Dynare …
Starting preprocessing of the model file …
ERROR: mletry3.mod:69.9: syntax error, unexpected ‘:’
??? Error using ==> dynare
DYNARE: preprocessing failed
It seems that Dynare does not accept ':'. However, this is the way that matlab uses to express all columns (or all rows). Thus it is not clear to me why Dynare does not accept ':'. Could this be a bug in Dynare?
I have some “new” findings about this problem. When I use Dynare v.3.065, it works!!! However, the procedure fails in v.4. It seems that version 4 does not recognize the colon operator, and this is weird.
May I ask a related question? I have to estimate the model for 1,000 times. However, MLE in Dynare seems pretty slow. In some preliminary trials, it could take 17-18 mins to finish one estimation. When I do this, I already incorporate the options like "nograph", "noprint", ... to expedite the process, but it is still quite time-consuming. Thus I would like to know if there are other ways to make MLE much faster (say, limit the number of iterations...). Thank you very much.
Actually your problem comes from the fact that in some circumstances, it is difficult for Dynare to distinguish between Matlab statements and Dynare statements: mixing both of them in the same file is a kind of hack. The code that I gave you doesn’t work in v4 because there is a name clash between Dynare endogenous variables, and Matlab variables.
I think that the following code should work in v4 (at last!):
load gaponetry;
for i=1:1000
datastruct.y = y1(:,i);
datastruct.pi = pi1(:,i);
datastruct.r = r1(:,i);
datastruct.g = g1(:,i);
datastruct.z = z1(:,i);
save mydata.mat -struct datastruct;
estimation(datafile=mydata,nograph);
end
(the idea is to enclose data variables within a structure, to avoid the name clash).