Real Time Estimation

Hello Everyone,

I am estimating a dsge model using a real time recursive data set that shifts one period ahead every period, so I specify the data as follows:

for i = 94:107
    for j = 1:4
       
       cl = clock;
       display(['day ', num2str(cl(3)), ' hour ', num2str(cl(4)), ' minute ', num2str(cl(5))])
       display(['file: data',num2str(i),'q',num2str(j)])
       
        
       datafile=['data',num2str(i),'q',num2str(j)];
       nobs = 119 + 4*(i-94) + (j-1);
       save options_dsge.mat datafile nobs i j counter;
       dynare sw2007nw_dsge;
       
       copyfile('sw2007nw_dsge/metropolis/sw2007nw_dsge_mh*',['dsge/',num2str(i),'q',num2str(j)]);
       global M_ dr1_test ex0_ it_ oo_recursive_  trend_coeff_ bayestopt_  estim_params_  fjac  oo_ options_ ys0_  
       save(['dsge/',num2str(i),'q',num2str(j),'/results.mat']);   
       
       rmdir('sw2007nw_dsge','s')
       % rmdir('dynareParallelLogFiles','s')
       close all
       
       counter = counter + 1;    
       
    end
end

To use this in the estimation, I do the following in the .mod file:

load options_dsge;
options_.datafile=datafile;
//recursive scheme 
options_.nobs      = nobs;
options_.first_obs = 1;


estimation(mode_compute=4,datafile='datafile',mode_file=sw2007nw_dsge_mode,nodiagnostic,mh_replic=31250,mh_nblocks=4,mh_jscale=0.35,mh_drop=0.2,bayesian_irf,irf=40);

However, this gives me the following error:

Error using makedataset (line 108)
makedataset: I can't find a datafile (with allowed extension m, mat, csv, xls or xlsx)!
Error in dynare_estimation_init (line 553)
[dataset_, dataset_info, newdatainterfaceflag] = makedataset(options_, options_.dsge_var*options_.dsge_varlag,
gsa_flag);
Error in dynare_estimation_1 (line 112)
    dynare_estimation_init(var_list_, dname, [], M_, options_, oo_, estim_params_, bayestopt_);
Error in dynare_estimation (line 105)
    dynare_estimation_1(var_list,dname);
Error in sw2007nw_dsge.driver (line 762)
oo_recursive_=dynare_estimation(var_list_);
Error in dynare (line 293)
evalin('base',[fname '.driver']) ;
Error in run_dsge (line 24)
       dynare sw2007nw_dsge; 

Could anyone please help?

Thank you
M

Have you tried providing an explicit file ending?

Dear Prof. Pfeifer,

I tried that, but did not work. I have attached the codes, if you could please have a look.
Forum.zip (619.7 KB)

Thank you in advance.

Best regards
M

The cleanest version is with macro switches when invoking Dynare:

for i = 94:107
    for j = 1:4
       
       cl = clock;
       display(['day ', num2str(cl(3)), ' hour ', num2str(cl(4)), ' minute ', num2str(cl(5))])
       display(['file: data',num2str(i),'q',num2str(j)])
       
        
       datafile_string=['data',num2str(i),'q',num2str(j),'.mat'];
       nobs = 119 + 4*(i-94) + (j-1);
       eval(['dynare sw2007nw_dsge -Ddatafile_name="',datafile_string,'" -Dnobs_counter=' num2str(nobs)])

where the estimation command then is

estimation(mode_compute=4,datafile='@{datafile_name}',nobs=@{nobs_counter},nodiagnostic,mh_replic=31250,mh_nblocks=4,mh_jscale=0.35,mh_drop=0.2,bayesian_irf,irf=40) dlGDP dlCONS dlINV dlWAG lHOURS dlP FEDFUNDS y pic r;

run_dsge.m (976 Bytes)
sw2007nw_dsge.mod (11.6 KB)

Dear Prof. Pfeifer,

Thank you so much for this. It works and estimates the model over the first dataset, but when it reaches line 19 of your code, it gives the error /dsge/94q1 is not in a directory.

Best Regards
M

Which operating system are you using? You may need

       if ~isfolder(['dsge/',num2str(i),'q',num2str(j)])
           mkdir(['dsge/',num2str(i),'q',num2str(j)])
       end

to create the necessary folder.
run_dsge.m (911 Bytes)

Dear Prof. Pfeifer,

I tried running the code in Windows computer and both of the above work well, but fail when I run them in Mac. Since I have the option to use Windows, I will stick to it.
Thank you for your time and help.

Best Regards,
M

Dear Prof. Pfeifer,

In addition to above, if I want to add option of first_obs and dsge_varlag as follows:


for dsge_varlag = [2 4 6 8];
counter=0;
for i=94:107
    for j=1:4 cl = clock;
       display(['day ', num2str(cl(3)), ' hour ', num2str(cl(4)), ' minute ', num2str(cl(5))])
       display(['file: data',num2str(i),'q',num2str(j)])

       datafile_string=['data',num2str(i),'q',num2str(j),'.mat'];
       nobs = 119 + 4*(i-94) + (j-1)-dsge_varlag;
       first_obs = 1+dsge_varlag;
       eval(['dynare dsge_dvars -Ddatafile_name="',datafile_string,'" -Dnobs_counter=' num2str(nobs),'" -Dfirst_obs_counter=' num2str(first_obs),'" -Ddsge_varlag_counter=' num2str(dsge_varlag)])
        
        copyfile('dsge_dvars/metropolis/Internal_FHL_dvars_mh*',['dvar',num2str(dsge_varlag),'/',num2str(i),'q',num2str(j)]);
        if ~isfolder(['dvar/',num2str(i),'q',num2str(j)])
            mkdir(['dvar/',num2str(i),'q',num2str(j)])
        end
        save(['dvar',num2str(dsge_varlag),'/',num2str(i),'q',num2str(j),'/results.mat']); 
        
        rmdir('dsge_dvars','s')
    
        close all
        
        counter = counter + 1;     
 
     end
 end
 
end

And I modified the estimation command as:

estimation(
    mode_compute=4,
    datafile='@{datafile_name}',
    nobs=@{nobs_counter},
    first_obs= @{first_obs_counter}
    dsge_varlag= @{dsge_varlag_counter}
    nodiagnostic,
    mh_replic=10000,
    mh_nblocks=2,
    mh_jscale=0.40,
    mh_drop=0.4,
    bayesian_irf,
    irf=40,
    nograph,
    dsge_var)

However, it seems like I am doing something wrong with the eval or the estimation command. Could you please check and help.

Best Regards,
M

Hi again,

Could you please help?
Thank you
M

I think it should be

eval(['dynare dsge_dvars -Ddatafile_name="',datafile_string,'" -Dnobs_counter=' num2str(nobs),' -Dfirst_obs_counter=' num2str(first_obs),' -Ddsge_varlag_counter=' num2str(dsge_varlag)])