Repeatedly estimate DSGE model using Dynare

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Repeatedly estimate DSGE model using Dynare

Postby jygg1 » Mon Dec 08, 2008 7:07 am

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
jygg1
 
Posts: 9
Joined: Thu Jul 10, 2008 1:40 am

Re: Repeatedly estimate DSGE model using Dynare

Postby SébastienVillemot » Mon Dec 08, 2008 5:12 pm

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
Sébastien Villemot
Economist at OFCE – Sciences Po
SébastienVillemot
 
Posts: 706
Joined: Fri Dec 07, 2007 2:29 pm
Location: Paris, France

Re: Repeatedly estimate DSGE model using Dynare

Postby jygg1 » Thu Dec 11, 2008 11:18 pm

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.
jygg1
 
Posts: 9
Joined: Thu Jul 10, 2008 1:40 am

Re: Repeatedly estimate DSGE model using Dynare

Postby jygg1 » Fri Dec 12, 2008 3:07 am

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.
jygg1
 
Posts: 9
Joined: Thu Jul 10, 2008 1:40 am

Re: Repeatedly estimate DSGE model using Dynare

Postby jygg1 » Thu Dec 18, 2008 9:32 am

Hi,

After many trials, I still cannot get Dynare to work. The attachment is my code. Any suggestions and advices are greatly appreciated.
Attachments
Mletry3.mod
(1.27 KiB) Downloaded 199 times
jygg1
 
Posts: 9
Joined: Thu Jul 10, 2008 1:40 am

Re: Repeatedly estimate DSGE model using Dynare

Postby SébastienVillemot » Thu Dec 18, 2008 9:57 am

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
Sébastien Villemot
Economist at OFCE – Sciences Po
SébastienVillemot
 
Posts: 706
Joined: Fri Dec 07, 2007 2:29 pm
Location: Paris, France

Re: Repeatedly estimate DSGE model using Dynare

Postby jygg1 » Fri Dec 19, 2008 8:37 am

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
jygg1
 
Posts: 9
Joined: Thu Jul 10, 2008 1:40 am

Re: Repeatedly estimate DSGE model using Dynare

Postby jygg1 » Sun Dec 21, 2008 12:02 am

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
jygg1
 
Posts: 9
Joined: Thu Jul 10, 2008 1:40 am

Re: Repeatedly estimate DSGE model using Dynare

Postby SébastienVillemot » Tue Dec 23, 2008 10:43 am

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
Sébastien Villemot
Economist at OFCE – Sciences Po
SébastienVillemot
 
Posts: 706
Joined: Fri Dec 07, 2007 2:29 pm
Location: Paris, France

Re: Repeatedly estimate DSGE model using Dynare

Postby jygg1 » Thu Dec 25, 2008 11:38 pm

Thank you very much. It works on version 4 now.

jygg1
jygg1
 
Posts: 9
Joined: Thu Jul 10, 2008 1:40 am


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 8 guests