Unverified Commit 9ddad32e authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Merge branch 'shock_decomp_fixes' of git.dynare.org:rattoma/dynare

Ref. !1829
parents 9d06016d 50e80fe4
......@@ -28,7 +28,9 @@ function WriteShockDecomp2Excel(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 <http://www.gnu.org/licenses/>.
SteadyState=[];
OutputDirectoryName = CheckPath('Output',DynareModel.dname);
SteadyState=zeros(DynareModel.endo_nbr,1);
fig_mode='';
fig_mode1='';
fig_name='';
......@@ -114,15 +116,13 @@ for j=1:nvar
end
warning off
try
[STATUS,MESSAGE] = xlswrite([DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1],d0,endo_names{i_var(j)});
catch
if exist('xlwrite.m','file')
[STATUS] = xlwrite([DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1],d0,endo_names{i_var(j)});
else
fprintf('\nWriteShockDecomp2Excel: could not write Excel file. It seems Excel is not installed on your machine.\n')
fprintf('Please install the free xlwrite.m from https://mathworks.com/matlabcentral/fileexchange/38591-xlwrite-generate-xls-x-files-without-excel-on-mac-linux-win\n')
end
fig_name1 = strrep(fig_name1,' ','_');
fig_name1 = strrep(fig_name1,'.','');
if ~ismac
[STATUS,MESSAGE] = xlswrite([OutputDirectoryName,filesep,DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1],d0,endo_names{i_var(j)});
else
writetable(cell2table(d0), [OutputDirectoryName,filesep,DynareModel.fname,'_shock_decomposition',fig_mode,fig_name1 '.xls'], 'Sheet', endo_names{i_var(j)},'WriteVariableNames',false);
end
warning on
......
function expand_group(use_shock_groups,var_list_, ic)
function expand_group(use_shock_groups,var_list_, ic, no_graph)
% function expand_group(use_shock_groups,var_list_, ic)
% Expands shocks contributions out of a group of shocks
%
......@@ -27,6 +27,9 @@ 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 <http://www.gnu.org/licenses/>.
if nargin<4
no_graph=0;
end
filename = get(gcf,'filename');
[filepath, name, ext]=fileparts(filename);
M = evalin('base','M_');
......@@ -56,7 +59,12 @@ M.exo_names = mydata.exo_names;
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;
if no_graph
options.no_graph.plot_shock_decomposition=1;
options.plot_shock_decomp.write_xls=1;
else
options.plot_shock_decomp.write_xls=0;
end
%% set optimal colormap
func = @(x) colorspace('RGB->Lab',x);
MAP = distinguishable_colors(length(shocks)+1,'w',func);
......
......@@ -227,6 +227,8 @@ for j=1:nvar
browse_menu = uimenu(c,'Label','Browse group');
expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(i) ')']);
set(expand_menu,'UserData',mydata,'Tag',['group' int2str(i)]);
save_expand2xls_menu = uimenu(c,'Label','Export group to xls','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(i) ', 1)']);
set(save_expand2xls_menu,'Tag',['xls_group' int2str(i)]);
for jmember = mydata.shock_group.shocks
uimenu('parent',browse_menu,'Label',char(jmember))
end
......
......@@ -24,7 +24,7 @@ function []=graph_decomp_detail(z,shock_names,endo_names,i_var,initial_date,Dyna
% 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.
%xf
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
......@@ -233,6 +233,8 @@ for j=1:nvar
browse_menu = uimenu(c,'Label','Browse group');
expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(ic) ')']);
set(expand_menu,'UserData',mydata,'Tag',['group' int2str(ic)]);
save_expand2xls_menu = uimenu(c,'Label','Export group to xls','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(ic) ', 1)']);
set(save_expand2xls_menu,'Tag',['xls_group' int2str(ic)]);
for jmember = mydata.shock_group.shocks
uimenu('parent',browse_menu,'Label',char(jmember))
end
......
......@@ -50,7 +50,7 @@ if size(varlist,1) == 0
end
end
if isfield(options_.plot_shock_decomp,'init2shocks') % private trap for uimenu calls
if isfield(options_.plot_shock_decomp,'init2shocks') && options_.plot_shock_decomp.realtime==0 % private trap for uimenu calls
init2shocks=options_.plot_shock_decomp.init2shocks;
else
init2shocks=[];
......@@ -59,7 +59,7 @@ if ~isempty(init2shocks)
init2shocks=M_.init2shocks.(init2shocks);
end
orig_endo_names = M_.endo_names;
epilogue_decomp=false;
if exist_varlist && any(ismember(varlist,M_.epilogue_names))
epilogue_decomp=true;
......@@ -252,15 +252,15 @@ 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');
j=strmatch(init2shocks{i}{1},orig_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,:);
M_.exo_names_init{jj}=[M_.exo_names_init{jj} ' + ' orig_endo_names{j}];
z(:,jj,:)= z(:,jj,:) + oo_.initval_decomposition (:,j,1:size(z,3));
else
z(:,end,:)= z(:,end,:) - oo_.initval_decomposition (:,j,:);
z(:,end,:)= z(:,end,:) - oo_.initval_decomposition (:,j,1:size(z,3));
end
z(:,end-1,:)= z(:,end-1,:) - oo_.initval_decomposition (:,j,:);
z(:,end-1,:)= z(:,end-1,:) - oo_.initval_decomposition (:,j,1:size(z,3));
end
end
......@@ -271,6 +271,9 @@ if ~epilogue_decomp
else
steady_state = oo_.steady_state;
end
if isfield(oo_.shock_decomposition_info,'i_var') && (M_.endo_nbr<length(orig_endo_names))
steady_state=steady_state(oo_.shock_decomposition_info.i_var);
end
else
steady_state = oo_.shock_decomposition_info.epilogue_steady_state;
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment