Page 1 of 1

Repeatedly estimate DSGE model using Dynare

PostPosted: Mon Dec 08, 2008 7:07 am
by jygg1
Hello,

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:
Code: Select all
@#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.

jygg1

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Mon Dec 08, 2008 5:12 pm
by SébastienVillemot
Hi

First, you don't need the macro-language for this kind of task, it would repeat the command 1000 times instead of putting it in a Matlab loop.

Second, you can't specify a sub-matrix as argument of "datafile=". You should create the appropriate MAT-file at each iteration.

Try the following:

Code: Select all
for i = 1:1000
  mydata2 = mydata(y1(:,i),c1(:,i),pi1(:,i),r1(:,i),g1(:,i),z1(:,i));
  save mydata3.mat mydata2;
  estimation(datafile=mydata3,nograph);
end


Best

Sébastien

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Thu Dec 11, 2008 11:18 pm
by jygg1
Hi Sébastien,

Thanks for your help. But I tried many times, the program still cannot work. The error message is:

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

Configuring Dynare ...
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.

Starting Dynare ...
Starting preprocessing of the model file ...
8 equation(s) found
Processing derivation ...
Processing Order 1... done
Processing Order 2... done
Processing outputs ...
Preprocessing completed.
Starting Matlab computing ...

??? Undefined variable y1.

Error in ==> mletry3 at 173
mydata2=mydata(y1(:,i),c1(:,i),pi1(:,i),r1(:,i),g1(:,i),z1(:,i));

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

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

It seems not clear to me why it is still a problem. Could you help me on this? I will also appreciate the help from others. Thank you very much.

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Fri Dec 12, 2008 3:07 am
by jygg1
After some trials, I modify my code as follows:

Code: Select all
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.

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Thu Dec 18, 2008 9:32 am
by jygg1
Hi,

After many trials, I still cannot get Dynare to work. The attachment is my code. Any suggestions and advices are greatly appreciated.

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Thu Dec 18, 2008 9:57 am
by SébastienVillemot
Hi

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:

Code: Select all
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


Best

Sébastien

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Fri Dec 19, 2008 8:37 am
by jygg1
Hi Sébastien,

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?

jygg1

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Sun Dec 21, 2008 12:02 am
by jygg1
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.

jygg1

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Tue Dec 23, 2008 10:43 am
by SébastienVillemot
Hi

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!):
Code: Select all
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).

Best

Sébastien

Re: Repeatedly estimate DSGE model using Dynare

PostPosted: Thu Dec 25, 2008 11:38 pm
by jygg1
Thank you very much. It works on version 4 now.

jygg1