Post-dynare stoch_simul

This file has to be run after Dynare simulations have been computed. It is automatically launched in Dynare_Truncation.m. The file is not meant to be launched otherwise.

The file fills three objectives.

  1. Saving endogenous variables (in particular taxes and otheraggregate variables), so as to estimating the tax rule for the Reiter method.

  2. Saving IRFs data, so as to build nice graphs.

  3. Reporting some second-order moments.

Saving endogenous variables.

We save endogenous variables in the csv file endo_trunc.csv variable names are written as headers.

We start with writing headers.

fid = fopen('endo_trunc.csv','w'); 
for k = 1:(length(M_.endo_names)-1)
    fprintf(fid,'%s,',M_.endo_names{k});
end
fprintf(fid,'%s\n',M_.endo_names{length(M_.endo_names)});
fclose(fid);

We now append data append headers.

dlmwrite('endo_trunc.csv',oo_.endo_simul','-append');

Saving IRFs

We save data in the mat-file irfs_trunc.mat.

tmp = oo_.irfs;
save('irfs_trunc.mat','tmp')

Computing second-order moments

We compute second-order moments and display them in the command line.

We start with means and standard deviations.

fprintf('\n')

var_list = {"GDP","C","K"};
means = containers.Map;
for k = 1:length(M_.endo_names)
    var = M_.endo_names{k};
    if ismember(var, var_list);
        means(var) = oo_.steady_state(k);
    end
end


fprintf("%15s %15s %15s\n", "Variable", "Mean", "Std-dev/mean");
for k = 1:length(oo_.var_list)
    var = oo_.var_list{k};
    if ismember(var, var_list);
        fprintf("%15s %15.3f %15.3f %15.3f\n", var, means(var), 100*oo_.var(k,k)^0.5/oo_.mean(k), 100*oo_.var(k,k)^0.5/means(var));
    end
end
fprintf('\n\n')

We now report auto-correlations for variables in var_list.

var_list = {"GDP","C"};
indices = containers.Map;

for k = 1:length(oo_.var_list)
    var = oo_.var_list{k};
    if ismember(var, var_list);
        indices(var) = k; 
    end
end

fprintf("%15s %15s\n", "Variable","Autocorrel");
for i=1:length(var_list)
    k = indices(var_list{i});
    fprintf("%15s %15.3f\n", oo_.var_list{k}, 100*oo_.autocorr{1}(k,k));
end
fprintf('\n\n')

We finally report correlations between variables in var_list.

fprintf("%15s %15s %15s\n", "Variable 1","Variable 2","Correlation");
for i=1:length(var_list)    
    for j=1:length(var_list)
        if j<=i
            continue
        end
        k1 = indices(var_list{i});
        k2 = indices(var_list{j});
        fprintf("%15s %15s %15.3f\n", oo_.var_list{k1}, oo_.var_list{k2}, 100*oo_.var(k1,k2)/(oo_.var(k1,k1)*oo_.var(k2,k2))^0.5);
    end
end
fprintf('\n')