properly handle labelling, grouping and expand under init2shocks option

time-shift
Marco Ratto 2019-12-12 16:45:57 +01:00
parent 06c2b49897
commit 35b63e87d6
4 changed files with 48 additions and 47 deletions

View File

@ -51,6 +51,7 @@ 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);
end
M.exo_names = mydata.exo_names;
options.plot_shock_decomp.interactive=0;
options.plot_shock_decomp.expand=1;

View File

@ -51,25 +51,6 @@ if ~isempty(opts_decomp.type)
fig_mode = [fig_mode '_'];
end
if isfield(opts_decomp,'flip')
flip_decomp = opts_decomp.flip ;
else
flip_decomp = 0;
end
if flip_decomp
fig_mode1 = [fig_mode1 '_flip'];
fig_mode = [fig_mode 'flip_'];
end
if isfield(opts_decomp,'diff')
differentiate_decomp = opts_decomp.diff ;
else
differentiate_decomp = 0;
end
if differentiate_decomp
fig_mode1 = [fig_mode1 '_diff'];
fig_mode = [fig_mode 'diff_'];
end
if isfield(opts_decomp,'init_cond_decomp')
init_cond_decomp = opts_decomp.init_cond_decomp ;
else
@ -232,8 +213,9 @@ for j=1:nvar
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)};
mydata.endo_names = endo_names(i_var(j));
mydata.endo_names_tex = DynareModel.endo_names_tex(i_var(j));
mydata.exo_names = DynareModel.exo_names;
if ~isempty(mydata.shock_group.shocks)
c = uicontextmenu;
hl.UIContextMenu=c;
@ -266,8 +248,9 @@ for j=1:nvar
fprintf(fidTeX,' \n');
end
else
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,preamble_figname,endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
if ~isempty(DynareOptions.plot_shock_decomp.filepath)
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,preamble_figname,endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
end
end
end

View File

@ -53,25 +53,7 @@ if ~isempty(opts_decomp.type)
fig_mode1 = ['_' fig_mode];
fig_mode = [fig_mode '_'];
end
if isfield(opts_decomp,'flip')
flip_decomp = opts_decomp.flip ;
else
flip_decomp = 0;
end
if flip_decomp
fig_mode1 = [fig_mode1 '_flip'];
fig_mode = [fig_mode 'flip_'];
end
if isfield(opts_decomp,'diff')
differentiate_decomp = opts_decomp.diff ;
else
differentiate_decomp = 0;
end
if differentiate_decomp
fig_mode1 = [fig_mode1 '_diff'];
fig_mode = [fig_mode 'diff_'];
end
if isfield(opts_decomp,'init_cond_decomp')
init_cond_decomp = opts_decomp.init_cond_decomp ;
else
@ -232,8 +214,9 @@ for j=1:nvar
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)};
mydata.endo_names = endo_names(i_var(j));
mydata.endo_names_tex = DynareModel.endo_names_tex(i_var(j));
mydata.exo_names = DynareModel.exo_names;
if ~isempty(mydata.shock_group.shocks)
c = uicontextmenu;
hax.UIContextMenu=c;
@ -289,8 +272,9 @@ for j=1:nvar
fprintf(fidTeX,' \n');
end
else
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,preamble_figname,endo_names{i_var(j)},fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
if ~isempty(DynareOptions.plot_shock_decomp.filepath)
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,preamble_figname,endo_names{i_var(j)},fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
end
end
end
end

View File

@ -164,20 +164,21 @@ end
if ~isempty(init2shocks) && ~expand
n=size(init2shocks,1);
M_.exo_names_init=M_.exo_names;
for i=1:n
j=strmatch(init2shocks{i}{1},M_.endo_names,'exact');
if ~isempty(init2shocks{i}{2})
jj=strmatch(init2shocks{i}{2},M_.exo_names,'exact');
M_.exo_names_init{jj}=[M_.exo_names_init{jj} ' + ' M_.endo_names{j}];
z(:,jj,:)= z(:,jj,:) + oo_.initval_decomposition (:,j,:);
else
z(:,end,:)= z(:,end,:) - oo_.initval_decomposition (:,j,:);
end
z(:,end-1,:)= z(:,end-1,:) - oo_.initval_decomposition (:,j,:);
end
end
end
if isfield(oo_.dr,'ys')
steady_state = oo_.dr.ys;
else
@ -235,6 +236,7 @@ end
if ~expand
fig_name = fig_name1;
end
if options_.plot_shock_decomp.use_shock_groups
fig_name=[fig_name ' group ' options_.plot_shock_decomp.use_shock_groups];
if expand
@ -255,10 +257,28 @@ if options_.plot_shock_decomp.use_shock_groups
zfull = z;
[z, shock_names, M_] = make_the_groups(z,gend,endo_nbr,nshocks,M_,options_);
end
if ~isempty(init2shocks) && ~expand
M_.exo_names=M_.exo_names_init;
end
else
if ~isempty(init2shocks) && ~expand
M_.exo_names=M_.exo_names_init;
end
shock_names = M_.exo_names;
end
if ~expand
if flip_decomp
fig_name=[fig_name ' flip'];
end
if differentiate_decomp
fig_name=[fig_name ' diff'];
end
if ~isempty(init2shocks)
fig_name=[fig_name ' init2shocks'];
end
end
func = @(x) colorspace('RGB->Lab',x);
MAP = distinguishable_colors(size(z,2)-1,'w',func);
% MAP = [MAP; MAP(end,:)];
@ -417,6 +437,7 @@ 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
@ -435,18 +456,30 @@ 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;
shock_varexo = shock_ind;
for i=1:ngroups
shock_names{i} = (shock_groups.(shock_ind{i}).label);
if isfield(M_,'exo_names_init')
shock_varexo{i} = (shock_groups.(shock_ind{i}).shocks);
end
end
zz = zeros(endo_nbr,ngroups+2,gend);
kcum=[];
for i=1:ngroups
indx=0;
for j = shock_groups.(shock_ind{i}).shocks
k = find(strcmp(j,cellstr(M_.exo_names)));
if isfield(M_,'exo_names_init')
indx=indx+1;
shock_varexo{i}{indx} = M_.exo_names_init{k};
end
zz(:,i,:) = zz(:,i,:) + z(:,k,:);
z(:,k,:) = 0;
kcum = [kcum k];
end
if isfield(M_,'exo_names_init')
shock_groups.(shock_ind{i}).shocks = shock_varexo{i};
end
end
zothers = sum(z(:,1:nshocks,:),2);
shock_groups.(['group' int2str(ngroups+1)]).label = 'Others';