Adjust output of loglinear option to make clear when a logged variable is used

- use of function for getting labels will allow to accommodate https://git.dynare.org/Dynare/dynare/-/issues/349
- incidentally fixes a bug in the display of the simulated variance decomposition for observables with measurement error
time-shift
Johannes Pfeifer 2020-12-23 10:36:59 +01:00
parent 5deaca993b
commit 9c52aec23d
10 changed files with 109 additions and 33 deletions

View File

@ -39,7 +39,7 @@ options_.order = 1;
oo_.steady_state = oo_.dr.ys;
if ~options_.noprint
disp_steady_state(M_,oo_)
disp_steady_state(M_,oo_,options_)
for i=M_.orig_endo_nbr:M_.endo_nbr
if strmatch('mult_', M_.endo_names{i})
fprintf('%s \t\t %g\n', M_.endo_names{i}, oo_.dr.ys(i));

View File

@ -67,6 +67,9 @@ header_label_length=16; %default
for ii=1:length(ivar)
header_label_length = max(header_label_length,length(M_.endo_names{k1(ivar(ii))})+2);
end
if options_.loglinear
header_label_length=header_label_length+5;
end
header_label_format = sprintf('%%%ds',header_label_length);
value_format_float = sprintf('%%%d.6f',header_label_length);
value_format_zero = sprintf('%%%dd',header_label_length);
@ -83,8 +86,11 @@ else
aux_var_additional_characters=0;
end
var_name_width = max([cellofchararraymaxlength(M_.endo_names(k1(ivar))), cellofchararraymaxlength(M_.exo_names)]);
if options_.loglinear
var_name_width = max([cellofchararraymaxlength(M_.endo_names(k1(ivar)))+5, cellofchararraymaxlength(M_.exo_names)]);
else
var_name_width = max([cellofchararraymaxlength(M_.endo_names(k1(ivar))), cellofchararraymaxlength(M_.exo_names)]);
end
%deal with covariances
if order > 1
var_name_width=max(2*(var_name_width+aux_var_additional_characters)+2,20); %account for covariances, separated by comma
@ -99,7 +105,11 @@ disp('POLICY AND TRANSITION FUNCTIONS')
% variable names
str = char(32*ones(1,var_name_width));
for i=1:nvar
str = [str sprintf(header_label_format, M_.endo_names{k1(ivar(i))})];
if options_.loglinear
str = [str sprintf(header_label_format, ['log(',M_.endo_names{k1(ivar(i))},')'])];
else
str = [str sprintf(header_label_format, M_.endo_names{k1(ivar(i))})];
end
end
disp(str);
%
@ -138,7 +148,11 @@ for k=1:nx
else
str1 = subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2);
end
str = sprintf(label_format,str1);
if options_.loglinear
str = sprintf(label_format,['log(',str1,')']);
else
str = sprintf(label_format,str1);
end
for i=1:nvar
x = dr.ghx(ivar(i),k);
[str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_);

View File

@ -94,8 +94,8 @@ oo_.var(zero_variance_var_index,:)=0;
oo_.var(:,zero_variance_var_index)=0;
labels = M_.endo_names(ivar);
labels_TeX = M_.endo_names_tex(ivar);
labels=get_labels_transformed_vars(M_.endo_names,ivar,options_,false);
labels_TeX=get_labels_transformed_vars(M_.endo_names_tex,ivar,options_,true);
if ~options_.nomoments
z = [ m' s' s2' oo_.skewness oo_.kurtosis ];
@ -204,10 +204,11 @@ if ~options_.nodecomposition
headers = vertcat(' ', headers);
lh = cellofchararraymaxlength(M_.endo_names(ivar))+2;
dyntable(options_, title, vertcat(headers, 'Tot. lin. contr.'), ...
M_.endo_names(ivar), [oo_.variance_decomposition sum(oo_.variance_decomposition,2)], lh, 8, 2);
labels, [oo_.variance_decomposition sum(oo_.variance_decomposition,2)], lh, 8, 2);
if ME_present
headers_ME = vertcat(headers, 'ME');
dyntable(options_, [title,' WITH MEASUREMENT ERROR'], vertcat(headers_ME, 'Tot. lin. contr.'), M_.endo_names(ivar(index_subset)), ...
labels_obs=get_labels_transformed_vars(M_.endo_names,ivar(index_subset),options_,false);
dyntable(options_, [title,' WITH MEASUREMENT ERROR'], vertcat(headers_ME, 'Tot. lin. contr.'), labels_obs, ...
[oo_.variance_decomposition_ME sum(oo_.variance_decomposition_ME, 2)], lh, 8, 2);
end
if options_.TeX
@ -219,9 +220,10 @@ if ~options_.nodecomposition
labels_TeX, [oo_.variance_decomposition sum(oo_.variance_decomposition, 2)], lh, 8, 2);
if ME_present
headers_ME = vertcat(headers, 'ME');
labels_obs_TeX=get_labels_transformed_vars(M_.endo_names_tex,ivar(index_subset),options_,true);
dyn_latex_table(M_, options_, [title, ' WITH MEASUREMENT ERROR'], 'sim_var_decomp_ME', ...
vertcat(headers_ME, 'Tot. lin. contr.'), ...
labels_TeX(ivar(index_subset)), ...
labels_obs_TeX, ...
[oo_.variance_decomposition_ME sum(oo_.variance_decomposition_ME, 2)], lh, 8, 2);
end
end
@ -256,3 +258,4 @@ else
end
end

View File

@ -1,10 +1,11 @@
function disp_steady_state(M,oo)
% function disp_steady_state(M,oo)
function disp_steady_state(M,oo,options)
% function disp_steady_state(M,oo,options)
% computes and prints the steady state calculations
%
% INPUTS
% M structure of parameters
% oo structure of results
% options structure of options
%
% OUTPUTS
% none
@ -12,7 +13,7 @@ function disp_steady_state(M,oo)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2018 Dynare Team
% Copyright (C) 2001-2020 Dynare Team
%
% This file is part of Dynare.
%
@ -30,7 +31,11 @@ function disp_steady_state(M,oo)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
skipline()
disp('STEADY-STATE RESULTS:')
if options.loglinear
disp('STEADY-STATE RESULTS FOR THE UNLOGGED VARIABLES:')
else
disp('STEADY-STATE RESULTS:')
end
skipline()
endo_names = char(M.endo_names);
steady_state = oo.steady_state;

View File

@ -82,11 +82,11 @@ if size(stationary_vars, 1) > 0
end
title = add_filter_subtitle(title, options_);
headers = {'VARIABLE';'MEAN';'STD. DEV.';'VARIANCE'};
labels = M_.endo_names(ivar);
labels=get_labels_transformed_vars(M_.endo_names,ivar,options_,false);
lh = cellofchararraymaxlength(labels)+2;
dyntable(options_, title, headers, labels, z, lh, 11, 4);
if options_.TeX
labels = M_.endo_names_tex(ivar);
labels=get_labels_transformed_vars(M_.endo_names_tex,ivar,options_,true);
lh = cellofchararraymaxlength(labels)+2;
dyn_latex_table(M_, options_, title, 'th_moments', headers, labels, z, lh, 11, 4);
end
@ -102,8 +102,9 @@ if size(stationary_vars, 1) > 0
headers = M_.exo_names;
headers(M_.exo_names_orig_ord) = headers;
headers = vertcat(' ', headers);
lh = cellofchararraymaxlength(M_.endo_names(ivar(stationary_vars)))+2;
dyntable(options_, title, headers, M_.endo_names(ivar(stationary_vars)), 100*oo_.gamma_y{options_.ar+2}(stationary_vars,:), lh, 8, 2);
labels=get_labels_transformed_vars(M_.endo_names,ivar(stationary_vars),options_,false);
lh = cellofchararraymaxlength(labels)+2;
dyntable(options_, title, headers, labels, 100*oo_.gamma_y{options_.ar+2}(stationary_vars,:), lh, 8, 2);
if ME_present
if isoctave && octave_ver_less_than('6')
[stationary_observables, pos_index_subset] = intersect_stable(index_subset, stationary_vars);
@ -111,17 +112,19 @@ if size(stationary_vars, 1) > 0
[stationary_observables, pos_index_subset] = intersect(index_subset, stationary_vars, 'stable');
end
headers_ME = vertcat(headers, 'ME');
dyntable(options_, [title,' WITH MEASUREMENT ERROR'], headers_ME, M_.endo_names(ivar(stationary_observables)), ...
labels=get_labels_transformed_vars(M_.endo_names,ivar(stationary_observables),options_,false);
dyntable(options_, [title,' WITH MEASUREMENT ERROR'], headers_ME, labels, ...
oo_.variance_decomposition_ME(pos_index_subset,:), lh, 8, 2);
end
if options_.TeX
headers = M_.exo_names_tex;
headers = vertcat(' ', headers);
labels = M_.endo_names_tex(ivar(stationary_vars));
labels=get_labels_transformed_vars(M_.endo_names_tex,ivar(stationary_vars),options_,true);
lh = cellofchararraymaxlength(labels)+2;
dyn_latex_table(M_, options_, title, 'th_var_decomp_uncond', headers, labels, 100*oo_.gamma_y{options_.ar+2}(stationary_vars,:), lh, 8, 2);
if ME_present
headers_ME = vertcat(headers, 'ME');
labels=get_labels_transformed_vars(M_.endo_names_tex,ivar(stationary_observables),options_,true);
dyn_latex_table(M_, options_, [title,' WITH MEASUREMENT ERROR'], ...
'th_var_decomp_uncond_ME', headers_ME, labels, oo_.variance_decomposition_ME(pos_index_subset,:), lh, 8, 2);
end
@ -172,12 +175,12 @@ if ~options_.nocorr && size(stationary_vars, 1)>0
title = 'MATRIX OF CORRELATIONS';
end
title = add_filter_subtitle(title, options_);
labels = M_.endo_names(ivar(i1));
labels=get_labels_transformed_vars(M_.endo_names,ivar(i1),options_,false);
headers = vertcat('Variables', labels);
lh = cellofchararraymaxlength(labels)+2;
dyntable(options_, title, headers, labels, corr(i1,i1), lh, 8, 4);
if options_.TeX
labels = M_.endo_names_tex(ivar(i1));
labels=get_labels_transformed_vars(M_.endo_names_tex,ivar(i1),options_,true);
headers = vertcat('Variables', labels);
lh = cellofchararraymaxlength(labels)+2;
dyn_latex_table(M_, options_, title, 'th_corr_matrix', headers, labels, corr(i1,i1), lh, 8, 4);
@ -199,15 +202,15 @@ if options_.ar > 0 && size(stationary_vars, 1) > 0
title = 'COEFFICIENTS OF AUTOCORRELATION';
end
title = add_filter_subtitle(title, options_);
labels = M_.endo_names(ivar(i1));
labels=get_labels_transformed_vars(M_.endo_names,ivar(i1),options_,false);
headers = vertcat('Order ', cellstr(int2str([1:options_.ar]')));
lh = cellofchararraymaxlength(labels)+2;
dyntable(options_, title, headers, labels, z, lh, 8, 4);
if options_.TeX
labels = M_.endo_names_tex(ivar(i1));
labels=get_labels_transformed_vars(M_.endo_names_tex,ivar(i1),options_,true);
headers = vertcat('Order ', cellstr(int2str([1:options_.ar]')));
lh = cellofchararraymaxlength(labels)+2;
dyn_latex_table(M_, options_, title, 'th_autocorr_matrix', headers, labels, z, lh, 8, 4);
end
end
end
end

View File

@ -63,9 +63,12 @@ else
end
headers = vertcat(' ', headers);
lh = cellofchararraymaxlength(M_.endo_names(SubsetOfVariables))+2;
labels=get_labels_transformed_vars(M_.endo_names,SubsetOfVariables,options_,false);
lh = cellofchararraymaxlength(labels)+2;
if options_.TeX
labels_TeX = M_.endo_names_tex(SubsetOfVariables);
labels_TeX=get_labels_transformed_vars(M_.endo_names,SubsetOfVariables,options_,true);
lh = cellofchararraymaxlength(labels_TeX)+2;
end
@ -76,7 +79,7 @@ for i=1:length(Steps)
for j=1:shock_number
vardec_i(:,j) = 100*conditional_decomposition_array(:,i,j);
end
dyntable(options_, '', headers, M_.endo_names(SubsetOfVariables), vardec_i, lh, 8, 2);
dyntable(options_, '', headers, labels, vardec_i, lh, 8, 2);
if options_.TeX
dyn_latex_table(M_, options_, [title, '; Period ' int2str(Steps(i))], ['th_var_decomp_cond_h', int2str(Steps(i))], headers_TeX, labels_TeX, vardec_i, lh, 8, 2);
end

View File

@ -44,7 +44,7 @@ end
oo_.steady_state = oo_.dr.ys;
if ~options_.noprint
disp_steady_state(M_,oo_)
disp_steady_state(M_,oo_,options_)
for i=M_.orig_endo_nbr:M_.endo_nbr
if strmatch('mult_', M_.endo_names{i})
disp(sprintf('%s \t\t %g', M_.endo_names{i}, oo_.dr.ys(i)));

View File

@ -81,7 +81,7 @@ end
if info(1) == 0
if ~options_.noprint
disp_steady_state(M_,oo_);
disp_steady_state(M_,oo_,options_);
end
else
if ~options_.noprint

View File

@ -0,0 +1,46 @@
function labels=get_labels_transformed_vars(endo_names,var_indices,options_,TeX)
% function labels=get_labels_transformed_vars(endo_names,var_indices,options_,TeX)
% This function displays the conditional variance decomposition of a given state space model
% for a subset of endogenous variables.
%
% INPUTS
% endo_names [cell] cell array of variable names
% var_indices [double] vector of variable indices
% options_ [structure] Dynare structure containing the options
% TeX [boolean] indicator for TeX-output
% OUTPUTS
% labels [cell] cell array of variable labels
%
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if nargin<4
TeX=0;
end
if options_.loglinear
labels=[];
for var_iter=1:length(var_indices)
if TeX
labels{var_iter,1}=['\log(',endo_names{var_indices(var_iter)},')'];
else
labels{var_iter,1}=['log(',endo_names{var_indices(var_iter)},')'];
end
end
else
labels = endo_names(var_indices);
end
end

View File

@ -23,7 +23,7 @@
*/
var y, c, k, a, h, b;
var y $y$, c $c$, k $k$, a , h, b;
varexo e, u;
parameters beta, rho, alpha, delta, theta, psi, tau;
@ -57,13 +57,15 @@ a = 1;
b = 1;
end;
resid(1);
steady;
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;
stoch_simul(loglinear,order=1);
steady;
stoch_simul(loglinear,order=1,conditional_variance_decomposition=[1:2]);
forecast;
conditional_forecast_paths;