diff --git a/matlab/expand_group.m b/matlab/expand_group.m
index 1793c9c21..4700de889 100644
--- a/matlab/expand_group.m
+++ b/matlab/expand_group.m
@@ -10,7 +10,7 @@ function expand_group(use_shock_groups,var_list_, ic)
% SPECIAL REQUIREMENTS
% none
-% Copyright (C) 2016-2017 Dynare Team
+% Copyright (C) 2016-2018 Dynare Team
%
% This file is part of Dynare.
%
@@ -27,6 +27,8 @@ function expand_group(use_shock_groups,var_list_, ic)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see .
+filename = get(gcf,'filename');
+[filepath, name, ext]=fileparts(filename);
M = evalin('base','M_');
oo = evalin('base','oo_');
options = evalin('base','options_');
@@ -39,9 +41,12 @@ options.first_obs=mydata.first_obs;
options.nobs=mydata.nobs;
% define expanded group
label = mydata.shock_group.label;
+label = strrep(label,' ','_');
+label = strrep(label,'-','_');
shocks = mydata.shock_group.shocks;
options.plot_shock_decomp.fig_name = [mydata.fig_name '. Expand'];
-options.plot_shock_decomp.use_shock_groups = strrep(label,' ','_'); %[use_shock_groups_old int2str(ic)];
+options.plot_shock_decomp.use_shock_groups = label; %[use_shock_groups_old int2str(ic)];
+options.plot_shock_decomp.filepath = filepath;
for j=1:length(shocks)
M.shock_groups.(options.plot_shock_decomp.use_shock_groups).(['group' int2str(j)]).label=shocks{j};
M.shock_groups.(options.plot_shock_decomp.use_shock_groups).(['group' int2str(j)]).shocks=shocks(j);
@@ -49,4 +54,16 @@ end
options.plot_shock_decomp.interactive=0;
options.plot_shock_decomp.expand=1;
+options.plot_shock_decomp.nodisplay=0;
+options.plot_shock_decomp.write_xls=0;
+%% set optimal colormap
+func = @(x) colorspace('RGB->Lab',x);
+MAP = distinguishable_colors(length(shocks)+1,'w',func);
+MAP(end,:) = [0.7 0.7 0.7];
+
+options.plot_shock_decomp.colormap = MAP;
+
+options.plot_shock_decomp.endo_names = mydata.endo_names;
+options.plot_shock_decomp.endo_names_tex = mydata.endo_names_tex;
+
plot_shock_decomposition(M,oo,options,var_list_);
diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m
index eda542009..ea3e1ebe4 100644
--- a/matlab/graph_decomp.m
+++ b/matlab/graph_decomp.m
@@ -28,7 +28,9 @@ function []=graph_decomp(z,shock_names,endo_names,i_var,initial_date,DynareModel
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see .
-GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
+if ~DynareOptions.plot_shock_decomp.expand
+ GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
+end
new_colormap = DynareOptions.plot_shock_decomp.colormap;
% number of components equals number of shocks + 1 (initial conditions)
@@ -87,7 +89,7 @@ end
nvar = length(i_var);
%% write LaTeX-Header
-if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
+if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand
fidTeX = fopen([GraphDirectoryName, filesep, DynareModel.fname '_shock_decomp' fig_mode1 fig_name '.tex'],'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp.m.\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
@@ -197,6 +199,9 @@ for j=1:nvar
mydata.plot_shock_decomp = DynareOptions.plot_shock_decomp;
mydata.first_obs = DynareOptions.first_obs;
mydata.nobs = DynareOptions.nobs;
+ mydata.plot_shock_decomp.zfull = DynareOptions.plot_shock_decomp.zfull(i_var(j),:,:);
+ mydata.endo_names = endo_names{i_var(j)};
+ mydata.endo_names_tex = DynareModel.endo_names_tex{i_var(j)};
if ~isempty(mydata.shock_group.shocks)
c = uicontextmenu;
hl.UIContextMenu=c;
@@ -216,20 +221,26 @@ for j=1:nvar
colormap(new_colormap)
end
hold off
- dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
- if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
- fprintf(fidTeX,'\\begin{figure}[H]\n');
- fprintf(fidTeX,'\\centering \n');
- fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[endo_names{i_var(j)} fig_mode1 fig_name]);
- fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',[fig_mode endo_names{i_var(j)} fig_name]);
- fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $.}\n'],DynareModel.endo_names_tex{i_var(j)});
- fprintf(fidTeX,'\\end{figure}\n');
- fprintf(fidTeX,' \n');
+ if ~DynareOptions.plot_shock_decomp.expand
+
+ dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
+ if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
+ fprintf(fidTeX,'\\begin{figure}[H]\n');
+ fprintf(fidTeX,'\\centering \n');
+ fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[endo_names{i_var(j)} fig_mode1 fig_name]);
+ fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',[fig_mode endo_names{i_var(j)} fig_name]);
+ fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $.}\n'],DynareModel.endo_names_tex{i_var(j)});
+ fprintf(fidTeX,'\\end{figure}\n');
+ fprintf(fidTeX,' \n');
+ end
+ else
+ dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,'_shock_decomposition_',endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
+
end
end
%% write LaTeX-Footer
-if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
+if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand
fprintf(fidTeX,' \n');
fprintf(fidTeX,'%% End of TeX file.\n');
fclose(fidTeX);
diff --git a/matlab/graph_decomp_detail.m b/matlab/graph_decomp_detail.m
index 9b920770b..d20997640 100644
--- a/matlab/graph_decomp_detail.m
+++ b/matlab/graph_decomp_detail.m
@@ -28,7 +28,9 @@ function []=graph_decomp_detail(z,shock_names,endo_names,i_var,initial_date,Dyna
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see .
-GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
+if ~DynareOptions.plot_shock_decomp.expand
+ GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
+end
% interactive = 0;
fig_mode='';
fig_mode1='';
@@ -108,7 +110,7 @@ end
nvar = length(i_var);
%% write LaTeX-Header
-if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
+if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand
fidTeX = fopen([GraphDirectoryName, filesep, DynareModel.fname '_shock_decomp' fig_mode1 fig_name '_detail.tex'],'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp_detail.m.\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
@@ -199,6 +201,9 @@ for j=1:nvar
mydata.plot_shock_decomp = DynareOptions.plot_shock_decomp;
mydata.first_obs = DynareOptions.first_obs;
mydata.nobs = DynareOptions.nobs;
+ mydata.plot_shock_decomp.zfull = DynareOptions.plot_shock_decomp.zfull(i_var(j),:,:);
+ mydata.endo_names = endo_names{i_var(j)};
+ mydata.endo_names_tex = DynareModel.endo_names_tex{i_var(j)};
if ~isempty(mydata.shock_group.shocks)
c = uicontextmenu;
hax.UIContextMenu=c;
@@ -241,22 +246,27 @@ for j=1:nvar
else
suffix = ['_detail'];
end
- dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname, ...
+ if ~DynareOptions.plot_shock_decomp.expand
+ dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname, ...
'_shock_decomposition_', endo_names{i_var(j)}, fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
- if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
- fprintf(fidTeX,'\\begin{figure}[H]\n');
- fprintf(fidTeX,'\\centering \n');
- fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[endo_names{i_var(j)} fig_mode1 fig_name suffix]);
- fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode endo_names{i_var(j)} fig_name suffix]);
- fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $ (detail).}\n'], DynareModel.endo_names_tex{i_var(j)});
- fprintf(fidTeX,'\\end{figure}\n');
- fprintf(fidTeX,' \n');
+ if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
+ fprintf(fidTeX,'\\begin{figure}[H]\n');
+ fprintf(fidTeX,'\\centering \n');
+ fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[endo_names{i_var(j)} fig_mode1 fig_name suffix]);
+ fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode endo_names{i_var(j)} fig_name suffix]);
+ fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $ (detail).}\n'], DynareModel.endo_names_tex{i_var(j)});
+ fprintf(fidTeX,'\\end{figure}\n');
+ fprintf(fidTeX,' \n');
+ end
+ else
+ dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,'_shock_decomposition_',endo_names{i_var(j)},fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
+
end
end
end
%% write LaTeX-Footer
-if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
+if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand
fprintf(fidTeX,' \n');
fprintf(fidTeX,'%% End of TeX file.\n');
fclose(fidTeX);
diff --git a/matlab/plot_shock_decomposition.m b/matlab/plot_shock_decomposition.m
index 0c4e42044..4df46ec67 100644
--- a/matlab/plot_shock_decomposition.m
+++ b/matlab/plot_shock_decomposition.m
@@ -50,6 +50,7 @@ if isfield(options_.plot_shock_decomp,'expand') % private trap for uimenu calls
expand=options_.plot_shock_decomp.expand;
else
expand=0;
+ options_.plot_shock_decomp.expand=0;
end
if ~isempty(options_.plot_shock_decomp.fig_name)
@@ -88,106 +89,132 @@ else
end
switch realtime_
-
- case 0
- z = oo_.shock_decomposition;
- fig_name1=fig_name;
-
- case 1 % realtime
- if vintage_
- z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]);
- fig_name1=[fig_name ' realtime (vintage ' char(initial_date+vintage_-1) ')'];
- else
- z = oo_.realtime_shock_decomposition.pool;
- fig_name1=[fig_name ' realtime (rolling)'];
- end
-
- case 2 % conditional
- if vintage_
- z = oo_.realtime_conditional_shock_decomposition.(['time_' int2str(vintage_)]);
- initial_date = initial_date+vintage_-1;
- fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead conditional forecast (given ' char(initial_date) ')'];
- else
- z = oo_.conditional_shock_decomposition.pool;
- fig_name1=[fig_name ' 1-step ahead conditional forecast (rolling)'];
- end
-
- case 3 % forecast
- if vintage_
- z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]);
- initial_date = initial_date+vintage_-1;
- fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead forecast (given ' char(initial_date) ')'];
- else
- z = oo_.realtime_forecast_shock_decomposition.pool;
- fig_name1=[fig_name ' 1-step ahead forecast (rolling)'];
- end
+
+ case 0
+ if ~expand
+ z = oo_.shock_decomposition;
+ end
+ fig_name1=fig_name;
+
+ case 1 % realtime
+ if vintage_
+ if ~expand
+ z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]);
+ end
+ fig_name1=[fig_name ' realtime (vintage ' char(initial_date+vintage_-1) ')'];
+ else
+ if ~expand
+ z = oo_.realtime_shock_decomposition.pool;
+ end
+ fig_name1=[fig_name ' realtime (rolling)'];
+ end
+
+ case 2 % conditional
+ if vintage_
+ if ~expand
+ z = oo_.realtime_conditional_shock_decomposition.(['time_' int2str(vintage_)]);
+ end
+ initial_date = initial_date+vintage_-1;
+ fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead conditional forecast (given ' char(initial_date) ')'];
+ else
+ if ~expand
+ z = oo_.conditional_shock_decomposition.pool;
+ end
+ fig_name1=[fig_name ' 1-step ahead conditional forecast (rolling)'];
+ end
+
+ case 3 % forecast
+ if vintage_
+ if ~expand
+ z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]);
+ end
+ initial_date = initial_date+vintage_-1;
+ fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead forecast (given ' char(initial_date) ')'];
+ else
+ if ~expand
+ z = oo_.realtime_forecast_shock_decomposition.pool;
+ end
+ fig_name1=[fig_name ' 1-step ahead forecast (rolling)'];
+ end
end
-steady_state = oo_.steady_state;
+if isfield(oo_.dr,'ys')
+ steady_state = oo_.dr.ys;
+else
+ steady_state = oo_.steady_state;
+end
-if isequal(type,'aoa') && isstruct(q2a) && realtime_
- % take all dates where realtime is saved
- qqq=options_.initial_date+options_.shock_decomp.save_realtime(:)-1;
- % take the first Q4 of saved realtime
- t0=min(options_.shock_decomp.save_realtime(qqq.time(:,2)==4));
- if isempty(t0)
- error('the realtime decompositions are not stored in Q4! Please check your dates and settings.')
+if isequal(type,'aoa') && isstruct(q2a)
+ if expand
+ za = options_.plot_shock_decomp.zfull;
+ genda = size(za,3);
+ endo_nbra = size(za,1);
+ [za, shock_names, M_] = make_the_groups(za,genda,endo_nbra,nshocks,M_, options_);
end
- if ~isfield(q2a,'var_type') % private trap for aoa calls
- q2a.var_type=1;
+ if realtime_
+ % take all dates where realtime is saved
+ qqq=options_.initial_date+options_.shock_decomp.save_realtime(:)-1;
+ % take the first Q4 of saved realtime
+ t0=min(options_.shock_decomp.save_realtime(qqq.time(:,2)==4));
+ if isempty(t0)
+ error('the realtime decompositions are not stored in Q4! Please check your dates and settings.')
+ end
+ if ~isfield(q2a,'var_type') % private trap for aoa calls
+ q2a.var_type=1;
+ end
+ if ~isfield(q2a,'islog') % private trap for aoa calls
+ q2a.islog=0;
+ end
+ if ~isfield(q2a,'GYTREND0') % private trap for aoa calls
+ q2a.GYTREND0=0;
+ end
+ if ~isfield(q2a,'aux') % private trap for aoa calls
+ q2a.aux=0;
+ end
+ if ~isfield(q2a,'cumfix') % private trap for aoa calls
+ q2a.cumfix=1;
+ end
+ if ~isfield(q2a,'plot') % private trap for aoa calls
+ q2a.plot=1; % growth rate
+ end
+
+ if ~expand
+ if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups)
+ mygroup = options_.plot_shock_decomp.use_shock_groups;
+ options_.plot_shock_decomp.use_shock_groups='';
+ zafull = ...
+ annualized_shock_decomposition(oo_,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a);
+ options_.plot_shock_decomp.use_shock_groups = mygroup;
+ end
+ [za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ...
+ annualized_shock_decomposition(oo_,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a);
+ end
end
- if ~isfield(q2a,'islog') % private trap for aoa calls
- q2a.islog=0;
- end
- if ~isfield(q2a,'GYTREND0') % private trap for aoa calls
- q2a.GYTREND0=0;
- end
- if ~isfield(q2a,'aux') % private trap for aoa calls
- q2a.aux=0;
- end
- if ~isfield(q2a,'cumfix') % private trap for aoa calls
- q2a.cumfix=1;
- end
- if ~isfield(q2a,'plot') % private trap for aoa calls
- q2a.plot=1; % growth rate
- end
- [za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ...
- annualized_shock_decomposition(oo_,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a);
end
if ~expand
fig_name = fig_name1;
end
-gend = size(z,3);
if options_.plot_shock_decomp.use_shock_groups
- shock_groups = M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups);
- shock_ind = fieldnames(shock_groups);
- ngroups = length(shock_ind);
fig_name=[fig_name ' group ' options_.plot_shock_decomp.use_shock_groups];
- shock_names = shock_ind;
- for i=1:ngroups
- shock_names{i} = (shock_groups.(shock_ind{i}).label);
- end
- zz = zeros(endo_nbr,ngroups+2,gend);
- kcum=[];
- for i=1:ngroups
- for j = shock_groups.(shock_ind{i}).shocks
- k = find(strcmp(j, M_.exo_names));
- zz(:,i,:) = zz(:,i,:) + z(:,k,:);
- z(:,k,:) = 0;
- kcum = [kcum k];
+ if expand
+ z = options_.plot_shock_decomp.zfull;
+ endo_names = options_.plot_shock_decomp.endo_names;
+ endo_names_tex = options_.plot_shock_decomp.endo_names_tex;
+ steady_state=steady_state(i_var);
+ i_var = 1;
+ if ~(isequal(type,'aoa') && isstruct(q2a))
+ gend = size(z,3);
+ endo_nbr = size(z,1);
+ [z, shock_names, M_] = make_the_groups(z,gend,endo_nbr,nshocks,M_,options_);
+ M_.endo_names = endo_names;
+ M_.endo_names_tex = endo_names_tex;
end
+ else
+ gend = size(z,3);
+ zfull = z;
+ [z, shock_names, M_] = make_the_groups(z,gend,endo_nbr,nshocks,M_,options_);
end
- zothers = sum(z(:,1:nshocks,:),2);
- shock_groups.(['group' int2str(ngroups+1)]).label = 'Others';
- shock_groups.(['group' int2str(ngroups+1)]).shocks = M_.exo_names(find(~ismember([1:M_.exo_nbr],kcum)));
- M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups)=shock_groups;
- if any(any(zothers))
- shock_names = [shock_names; {'Others + Initial Values'}];
- end
- zz(:,ngroups+1,:) = sum(z(:,1:nshocks+1,:),2);
- zz(:,ngroups+2,:) = z(:,nshocks+2,:);
- z = zz;
else
shock_names = M_.exo_names;
end
@@ -259,6 +286,7 @@ switch type
q2a.plot=1; % growth rate
end
+ if ~expand
if isstruct(q2a.aux) && ischar(q2a.aux.y)
opts=options_;
opts.plot_shock_decomp.type='qoq';
@@ -268,8 +296,19 @@ switch type
end
[za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ...
annualized_shock_decomposition(z,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a);
+ if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups)
+ mygroup = options_.plot_shock_decomp.use_shock_groups;
+ options_.plot_shock_decomp.use_shock_groups='';
+ zafull = ...
+ annualized_shock_decomposition(z,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a);
+ options_.plot_shock_decomp.use_shock_groups = mygroup;
+ end
+ end
end
z = za;
+ if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups)
+ zfull = zafull;
+ end
M_.endo_names = endo_names;
M_.endo_names_tex = endo_names_tex;
% endo_nbr = size(z,1);
@@ -324,6 +363,9 @@ z = z(:,:,a:b);
options_.plot_shock_decomp.fig_name=fig_name;
options_.plot_shock_decomp.orig_varlist = varlist;
+if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups)
+ options_.plot_shock_decomp.zfull = zfull;
+end
if detail_plot
graph_decomp_detail(z, shock_names, M_.endo_names, i_var, my_initial_date, M_, options_)
else
@@ -331,5 +373,39 @@ else
end
if write_xls
- WriteShockDecomp2Excel(z,shock_names,M_.endo_names,i_var,initial_date,M_,options_,options_.plot_shock_decomp);
+ WriteShockDecomp2Excel(z,shock_names,M_.endo_names,i_var,my_initial_date,M_,options_,options_.plot_shock_decomp);
+end
+
+end
+
+function [z, shock_names, M_] = make_the_groups(z,gend,endo_nbr,nshocks,M_,options_)
+
+shock_groups = M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups);
+shock_ind = fieldnames(shock_groups);
+ngroups = length(shock_ind);
+shock_names = shock_ind;
+for i=1:ngroups
+ shock_names{i} = (shock_groups.(shock_ind{i}).label);
+end
+zz = zeros(endo_nbr,ngroups+2,gend);
+kcum=[];
+for i=1:ngroups
+ for j = shock_groups.(shock_ind{i}).shocks
+ k = find(strcmp(j,cellstr(M_.exo_names)));
+ zz(:,i,:) = zz(:,i,:) + z(:,k,:);
+ z(:,k,:) = 0;
+ kcum = [kcum k];
+ end
+end
+zothers = sum(z(:,1:nshocks,:),2);
+shock_groups.(['group' int2str(ngroups+1)]).label = 'Others';
+shock_groups.(['group' int2str(ngroups+1)]).shocks = cellstr(M_.exo_names(find(~ismember([1:M_.exo_nbr],kcum)),:))';
+M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups)=shock_groups;
+if any(any(zothers))
+ shock_names = [shock_names; {'Others + Initial Values'}];
+end
+zz(:,ngroups+1,:) = sum(z(:,1:nshocks+1,:),2);
+zz(:,ngroups+2,:) = z(:,nshocks+2,:);
+z = zz;
+
end