Merge branch 'annual_shock_decomp' into 'master'

annualized_shock_decomposition.m: fix bug introduced in 735bd66d

Closes #1919

See merge request Dynare/dynare!2271
dprior
Sébastien Villemot 2024-01-29 17:10:32 +00:00
commit 6145bf9b31
2 changed files with 15 additions and 10 deletions

View File

@ -129,7 +129,7 @@ if realtime_==0
myopts=options_; myopts=options_;
myopts.plot_shock_decomp.type='qoq'; myopts.plot_shock_decomp.type='qoq';
myopts.plot_shock_decomp.realtime=0; myopts.plot_shock_decomp.realtime=0;
z = plot_shock_decomposition(M_,oo_,myopts,[]); z = plot_shock_decomposition(M_,oo_,myopts,[],true);
else else
z = oo_; z = oo_;
end end
@ -139,7 +139,7 @@ if realtime_==0
myopts=options_; myopts=options_;
myopts.plot_shock_decomp.type='qoq'; myopts.plot_shock_decomp.type='qoq';
myopts.plot_shock_decomp.realtime=0; myopts.plot_shock_decomp.realtime=0;
[y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux.y); [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux.y,true);
aux.y=y_aux; aux.y=y_aux;
aux.yss=steady_state_aux; aux.yss=steady_state_aux;
end end
@ -158,13 +158,13 @@ if realtime_ && isstruct(oo_) && isfield(oo_, 'realtime_shock_decomposition')
myopts.plot_shock_decomp.realtime=1; myopts.plot_shock_decomp.realtime=1;
myopts.plot_shock_decomp.vintage=i; myopts.plot_shock_decomp.vintage=i;
% retrieve quarterly shock decomp % retrieve quarterly shock decomp
z = plot_shock_decomposition(M_,oo_,myopts,[]); z = plot_shock_decomposition(M_,oo_,myopts,[],true);
zdim = size(z); zdim = size(z);
z = z(i_var,:,:); z = z(i_var,:,:);
if isstruct(aux) if isstruct(aux)
if ischar(aux0.y) if ischar(aux0.y)
% retrieve quarterly shock decomp for aux variable % retrieve quarterly shock decomp for aux variable
[y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux0.y); [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux0.y,true);
aux.y=y_aux; aux.y=y_aux;
aux.yss=steady_state_aux; aux.yss=steady_state_aux;
end end
@ -185,13 +185,13 @@ if realtime_ && isstruct(oo_) && isfield(oo_, 'realtime_shock_decomposition')
if qvintage_>i-4 && qvintage_<i if qvintage_>i-4 && qvintage_<i
myopts.plot_shock_decomp.vintage=qvintage_; myopts.plot_shock_decomp.vintage=qvintage_;
% retrieve quarterly shock decomp % retrieve quarterly shock decomp
z = plot_shock_decomposition(M_,oo_,myopts,[]); z = plot_shock_decomposition(M_,oo_,myopts,[],true);
z(:,:,end+1:zdim(3))=nan; % fill with nan's remaining time points to reach Q4 z(:,:,end+1:zdim(3))=nan; % fill with nan's remaining time points to reach Q4
z = z(i_var,:,:); z = z(i_var,:,:);
if isstruct(aux) if isstruct(aux)
if ischar(aux0.y) if ischar(aux0.y)
% retrieve quarterly shock decomp for aux variable % retrieve quarterly shock decomp for aux variable
[y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux0.y); [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux0.y,true);
y_aux(:,:,end+1:zdim(3))=nan; % fill with nan's remaining time points to reach Q4 y_aux(:,:,end+1:zdim(3))=nan; % fill with nan's remaining time points to reach Q4
aux.y=y_aux; aux.y=y_aux;
aux.yss=steady_state_aux; aux.yss=steady_state_aux;

View File

@ -1,4 +1,4 @@
function [out, steady_state] = plot_shock_decomposition(M_,oo_,options_,varlist) function [out, steady_state] = plot_shock_decomposition(M_,oo_,options_,varlist,get_decomp_only)
% function plot_shock_decomposition(M_,oo_,options_,varlist) % function plot_shock_decomposition(M_,oo_,options_,varlist)
% Plots the results of shock_decomposition % Plots the results of shock_decomposition
% %
@ -7,11 +7,12 @@ function [out, steady_state] = plot_shock_decomposition(M_,oo_,options_,varlist)
% oo_: [structure] Storage of results % oo_: [structure] Storage of results
% options_: [structure] Options % options_: [structure] Options
% varlist: [char] List of variables % varlist: [char] List of variables
% % get_decomp_only [bool] indicator on whether to only return with
% basic decomposition (required for e.g. annualized_shock_decomposition)
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright © 2016-2019 Dynare Team % Copyright © 2016-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -28,6 +29,10 @@ function [out, steady_state] = plot_shock_decomposition(M_,oo_,options_,varlist)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>. % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
if nargin<5
get_decomp_only=false;
end
options_.nodisplay = options_.plot_shock_decomp.nodisplay; options_.nodisplay = options_.plot_shock_decomp.nodisplay;
options_.graph_format = options_.plot_shock_decomp.graph_format; options_.graph_format = options_.plot_shock_decomp.graph_format;
@ -532,7 +537,7 @@ if steadystate
options_.plot_shock_decomp.steady_state=steady_state; options_.plot_shock_decomp.steady_state=steady_state;
end end
if nargout == 2 if get_decomp_only
out=z(i_var,:,:); out=z(i_var,:,:);
steady_state = steady_state(i_var); steady_state = steady_state(i_var);
return return