Debian Codegraph @

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

raw
1 function imf = zimpulse(Bh,swish,nn)
2 % Computing impulse functions with
3 % imf = zimpulse(Bh,swish,nn)
4 % where imf is in a format that is the SAME as in RATS.
5 % Column: nvar responses to 1st shock,
6 % nvar responses to 2nd shock, and so on.
7 % Row: steps of impulse responses.
8 % Bh is the estimated reduced form coefficient in the form
9 % Y(T*nvar) = XB + U, X: T*k, B: k*nvar. The matrix
10 % form or dimension is the same as "Bh" from the function "sye";
11 % swish is the inv(A0) in the structural model A(L)y(t) = e(t).
12 % nn is the numbers of inputs [nvar,lags,# of impulse responses].
13 % Written by Tao Zha
14 %
15 %
16 % Copyright (C) 1997-2012 Tao Zha
17 %
18 % This free software: you can redistribute it and/or modify
19 % it under the terms of the GNU General Public License as published by
20 % the Free Software Foundation, either version 3 of the License, or
21 % (at your option) any later version.
22 %
23 % It is distributed in the hope that it will be useful,
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of
25 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 % GNU General Public License for more details.
27 %
28 % If you did not received a copy of the GNU General Public License
29 % with this software, see <http://www.gnu.org/licenses/>.
30 %
31
32
33 nvar = nn(1);
34 lags = nn(2);
35 imstep = nn(3); % number of steps for impulse responses
36
37 Ah = Bh';
38 % Row: nvar equations
39 % Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k.
40
41 imf = zeros(imstep,nvar*nvar);
42 % Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on.
43 % Row: steps of impulse responses.
44 M = zeros(nvar*(lags+1),nvar);
45 % Stack lags M's in the order of, e.g., [Mlags, ..., M2,M1;M0]
46 M(1:nvar,:) = swish;
47 Mtem = M(1:nvar,:); % temporary M.
48 % first (initial) responses to 1 standard deviation shock. Row: responses; Column: shocks
49 % * put in the form of "imf"
50 imf(1,:) = Mtem(:)';
51
52 t = 1;
53 ims1 = min([imstep-1 lags]);
54 while t <= ims1
55 Mtem = Ah(:,1:nvar*t)*M(1:nvar*t,:);
56 % Row: nvar equations, each for the nvar variables at tth lag
57 M(nvar+1:nvar*(t+1),:)=M(1:nvar*t,:);
58 M(1:nvar,:) = Mtem;
59 imf(t+1,:) = Mtem(:)';
60 % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc.
61 t= t+1;
62 end
63
64 for t = lags+1:imstep-1
65 Mtem = Ah(:,1:nvar*lags)*M(1:nvar*lags,:);
66 % Row: nvar equations, each for the nvar variables at tth lag
67 M(nvar+1:nvar*(t+1),:) = M(1:nvar*t,:);
68 M(1:nvar,:)=Mtem;
69 imf(t+1,:) = Mtem(:)';
70 % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc.
71 end