Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_mimfgraph.m

raw
1 function scaleout = fn_mimfgraph(imfe,nvar,q_m,imstp,xlab,ylab,tlab,xTick)
2 % mimfgraph: multiple impulse functions plotted in subplots put in one chart.
3 %
4 % imfe: imstp-by-n^2+2-by-h series data with dates in the first 2 columns in the order of year and month (or quarter).
5 % imstp: the number of impulse response steps.
6 % nvar^2+2: n series plus the first 2 columns indicating dates. For the last nvar^2 columns,
7 % the order is: nvar responses to the 1st shock, ..., nvar responses to the last shock.
8 % h: The number of sereies on the 3rd dimension, put in the same subplot as in each of the n series.
9 % The first 2 columns in the 3rd dimension can be NaN while some other columns
10 % are also allowed to be NaN if no data are available.
11 % The last 2 columns in the 3rd dimension must be used for error bands if "area"
12 % is used to plot these bands.
13 % nvar: number of variables
14 % q_m: monthly (12) or quarterly (4)
15 % imstp: number of steps of impulse responses
16 % xlab,ylab,tlab: x-axis, y-axis, and title labels
17 % xTick: optional. Eg: [12 24 36].
18 %---------------
19 % scaleout: column 1 represents maximums; column 2 minimums. Rows: nvar variables.
20 %
21 % See ftd_mseriesgraph.m and fn_mseriesgraph.m
22 %
23 % Copyright (C) 1997-2012 Tao Zha
24 %
25 % This free software: you can redistribute it and/or modify
26 % it under the terms of the GNU General Public License as published by
27 % the Free Software Foundation, either version 3 of the License, or
28 % (at your option) any later version.
29 %
30 % It is distributed in the hope that it will be useful,
31 % but WITHOUT ANY WARRANTY; without even the implied warranty of
32 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 % GNU General Public License for more details.
34 %
35 % If you did not received a copy of the GNU General Public License
36 % with this software, see <http://www.gnu.org/licenses/>.
37 %
38
39
40 if nargin < 7, xTick = []; end
41
42 if nvar^2~=size(imfe,2)-2
43 disp(' ')
44 warning('The number of columns in imfe must be nvar^2+2 (columns of dates)')
45 disp('Press ctrl-c to abort')
46 pause
47 end
48
49
50
51 t = 1:imstp;
52 temp1=zeros(nvar,1);
53 temp2=zeros(nvar,1);
54 minval=zeros(nvar,1); % for each variable to nvar shocks
55 maxval=zeros(nvar,1); % for each variable to nvar shocks
56 for i = 1:nvar % variable
57 for j = 1:nvar % shock
58 tmpimf = squeeze(imfe(:,2+(j-1)*nvar+i,:));
59 temp1(j) = min(min(tmpimf));
60 temp2(j) = max(max(tmpimf));
61 end
62 minval(i)=min(temp1);
63 maxval(i)=max(temp2);
64 end
65
66 scaleout = [minval(:) maxval(:)];
67
68 %--------------
69 % Column j: Shocks 1 to N; Row i: Variable responses to
70 %-------------
71
72 rowlabel = 1;
73 for i = 1:nvar % variable
74 columnlabel = 1;
75
76 if minval(i)<0
77 if maxval(i)<=0
78 yt=[minval(i) 0];
79 else
80 yt=[minval(i) 0 maxval(i)];
81 end
82 else % (minval(i) >=0)
83 if maxval(i) > 0
84 yt=[0 maxval(i)];
85 else % (identically zero responses)
86 yt=[-1 0 1];
87 end
88 end
89
90 scale=[1 imstp minval(i) maxval(i)];
91 for j = 1:nvar % shock
92 k1=(i-1)*nvar+j;
93 k2=(j-1)*nvar+i;
94 subplot(nvar,nvar,k1)
95 if 0 % Plot area for error bands at the last two 3-rd dimensions.
96 area(imfe(:,1)+imfe(:,2)/q_m,squeeze(imfe(:,2+k2,end)),-100,'EdgeColor','none','FaceColor','y') % yellow
97 hold on
98 area(imfe(:,1)+imfe(:,2)/q_m,squeeze(imfe(:,2+k2,end-1)),-100,'EdgeColor','none','FaceColor',[1 1 1]) % white
99 set(gca,'ColorOrder',[0 0 0]); % turn the color off and set it to black
100 set(gca,'LineStyleOrder', '-|-.|--|:'); % cycle through the newly defined LineSytleOrder
101 plot(t,squeeze(imfe(:,2+k2,1:end-2)),t,zeros(length(imfe(:,k2)),1),'-');
102 set(gca,'Layer','top')
103 hold off
104 else % No error bands plotted
105 %=== set color to black and cycle through the newly defined LineSytleOrder
106 set(0,'DefaultAxesColorOrder',[0 0 0], ...
107 'DefaultAxesLineStyleOrder','-|-.|--|:')
108 %set(gca,'ColorOrder',[0 0 0]); % turn the color off and set it to black
109 %set(gca,'LineStyleOrder', '-|-.|--|:'); % cycle through the newly defined LineSytleOrder
110 plot(t,squeeze(imfe(:,2+k2,1:end)),t,zeros(length(imfe(:,k2)),1),'-');
111 end
112 if 1 % Get legends
113 if (i==2) & (j==3) % | (i==6)
114 legend('Const','S1','S2','S3',0)
115 % legend('Actual Data','Absent policy shocks',0)
116 end
117 end
118
119 set(gca,'XTick',xTick)
120 set(gca,'YTick',yt)
121 grid
122
123 axis(scale); % put limits on both axes.
124 %set(gca,'YLim',[minval(i) maxval(i)]) % put the limit only on the y-axis
125 if isempty(xTick) %1 % no numbers on axes
126 set(gca,'XTickLabel',' ');
127 set(gca,'YTickLabel',' ');
128 else % put numbers on both axes
129 if i<nvar
130 set(gca,'XTickLabelMode','manual','XTickLabel',[])
131 end
132 if j>1
133 set(gca,'YTickLabel',' ');
134 end
135 end
136
137 if rowlabel == 1
138 %title(['x' num2str(j)])
139 %title(eval(['x' num2str(j)]))
140 title(char(xlab(j)))
141 end
142 if columnlabel == 1
143 %ylabel(['x' num2str(i)])
144 %ylabel(eval(['x' num2str(i)]))
145 ylabel(char(ylab(i)))
146 end
147 columnlabel = 0;
148 end
149 rowlabel = 0;
150 end
151
152 subtitle(tlab)