Loop over data file name for estimation

I was wondering how to pass the name of the data file into the .mod file? Essentially, I want to run something like

for i = 1:N
    dynare model.mod (in which estimation(datafile = filename[i]); )
    ... (record the results)

Thank you!

One option is

This is adding some lines to some files. So what you mean is to create a new mod file every time in the loop? OK, thanks.

No, have a file e.g. called
estimation_statement.txt included in your mod-file with

@#include "estimation_statement.txt"

Then alter that file using the for-loop:

for ii=1:size(filenames,1)
%write equation to file
fprintf(fid,'estimation(datafile = %s)\n',filenames{ii,1});
%run file
dynare my_modfile noclearall
%save results

I see, through a macro. Thanks a lot for that clarification!