Debian Codegraph @

tests/ms-sbvar/archive-files/ftd_upperchol6v.m

raw
1 function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol6v(lags,nvar,nexo,indxC0Pres)
2 % vlist = [127 124 2 93 141 21]; % 1: Pcom 2 (exchange rate 21); 2: M3 141 (M2 140); 3: R; 4: GDP; 5: GDP deflator 124 (consumption deflator 79).
3 % varlist={'y', 'P', 'Pcom', 'R', 'M3', 'Ex'};
4 %
5 % Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
6 % See Waggoner and Zha's Gibbs sampling paper.
7 %
8 % q_m: quarter or month
9 % lags: the maximum length of lag
10 % nvar: number of endogeous variables
11 % nexo: number of exogenous variables. If nexo is not supplied, nexo=1 as default for a constant
12 % indxC0Pres: index for cross-A0-A+ restrictions. if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
13 % Example for indxOres==1: restrictions of the form P(t) = P(t-1).
14 % These restrictions have to be manually and carefully keyed in.
15 %-----------------
16 % Ui: nvar-by-1 cell. In each cell, nvar-by-qi orthonormal basis for the null of the ith
17 % equation contemporaneous restriction matrix where qi is the number of free parameters.
18 % With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
19 % of total original parameters and bi is a vector of free parameters. When no
20 % restrictions are imposed, we have Ui = I. There must be at least one free
21 % parameter left for the ith equation.
22 % Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith
23 % equation lagged restriction matrix where k is a total of exogenous variables and
24 % ri is the number of free parameters. With this transformation, we have fi = Vi*gi
25 % or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
26 % vector of free parameters. There must be at least one free parameter left for
27 % the ith equation.
28 % n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
29 % np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
30 % ixmC0Pres: neq_cres-by-1 cell. Effective only if indxC0Pres=1, otherwise equals NaN.
31 % neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
32 % In the jth cell representing equation, we have 4 columns:
33 % 1st: the jth column (equation) of A+ or A0: f_j or a_j
34 % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
35 % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
36 % 4th: the number s such that f_j(i) = s * a_j(h) holds.
37 %
38 % Tao Zha, May 2000
39
40
41
42 Ui = cell(nvar,1); % initializing for contemporaneous endogenous variables
43 Vi = cell(nvar,1); % initializing for lagged and exogenous variables
44 n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
45 np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
46
47 if (nargin==2)
48 nexo = 1; % 1: constant as default where nexo must be a nonnegative integer
49 elseif (nargin==3)
50 indxC0Pres = 0; % default is no cross-A0-and-A+ restrictions.
51 end
52
53 k = lags*nvar+nexo; % maximum number of lagged and exogenous variables in each equation
54
55 Qi = zeros(nvar,nvar,nvar); % for nvar contemporaneous equations
56 Ri = zeros(k,k,nvar); % for nvar lagged and exogenous equations
57 % Row corresponds to equation. 0 means no restriction.
58 % 1 means exclusion restriction such that the corresponding parameter is restricted to 0.
59
60 %nfvar = 6; % number of foreign (Granger causing) variables
61 %nhvar = nvar-nfvar; % number of home (affected) variables.
62
63
64 %-------------------------------------------------------------
65 % Beginning the manual input of the restrictions one quation at a time
66 %-------------------------------------------------------------
67 %
68 %======== The first equation ===========
69 Qi(1:5,:,1) = [
70 0 1 0 0 0 0
71 0 0 1 0 0 0
72 0 0 0 1 0 0
73 0 0 0 0 1 0
74 0 0 0 0 0 1
75 ];
76
77 %======== The second equation ===========
78 Qi(1:4,:,2) = [
79 0 0 1 0 0 0
80 0 0 0 1 0 0
81 0 0 0 0 1 0
82 0 0 0 0 0 1
83 ];
84
85 %======== The third equation ===========
86 Qi(1:3,:,3) = [
87 0 0 0 1 0 0
88 0 0 0 0 1 0
89 0 0 0 0 0 1
90 ];
91
92
93 %======== The fourth equation ===========
94 Qi(1:2,:,4) = [
95 0 0 0 0 1 0
96 0 0 0 0 0 1
97 ];
98
99
100 %======== The fifth equation ===========
101 Qi(1:1,:,5) = [
102 0 0 0 0 0 1
103 ];
104
105
106 %======== The sixth equation ===========
107
108 %===== Lagged restrictions in foreign (Granger causing) block
109 %nfbres = lags*(nvar-nfvar); % number of block restrictions in each foreign equation
110 %bfor = zeros(nfbres,k); % each foreign equation
111 %cnt=0;
112 %for ki = 1:lags
113 % for kj=1:nvar-nfvar
114 % cnt=cnt+1;
115 % bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
116 % end
117 %end
118 %%
119 %if cnt~=nfbres
120 % error('Check lagged restrictions in foreign equations!')
121 %end
122 %%
123 %for kj=1:nfvar
124 % Ri(1:nfbres,:,kj) = bfor;
125 %end
126
127
128 %===== Lagged restrictions in home (affected) block
129 %
130 %~~~~~ selected domestic equations
131 %dlrindx = nfvar+1; %[nfvar+1 nfvar+2]; % index for relevant home equations
132 %rfvindx = []; %[6]; %[1 2 3 5]; % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
133 %%nf2hvar = nfvar-length(rfvindx); % number of free parameters -- foreign variables entering the home sector
134 %nhbres = lags*length(rfvindx); % number of block restrictions in each home equation
135 %bhom = zeros(nhbres,k); % each home equation
136 %cnt=0;
137 %for ki = 1:lags
138 % for kj=1:length(rfvindx)
139 % cnt=cnt+1;
140 % bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
141 % end
142 %end
143 %%
144 %if cnt~=nhbres
145 % error('Check lagged restrictions in domestic equations!')
146 %end
147 %%
148 %for kj=dlrindx
149 % Ri(1:nhbres,:,kj) = bhom;
150 %end
151
152
153 for n=1:nvar % initializing loop for each equation
154 Ui{n} = null(Qi(:,:,n));
155 Vi{n} = null(Ri(:,:,n));
156 n0(n) = size(Ui{n},2);
157 np(n) = size(Vi{n},2);
158 end
159
160
161
162 %(2)-------------------------------------------------------------
163 % Cross-A0-and-A+ rerestrictions one quation at a time
164 % i.e., the first, second, ..., kjth, ..., equation
165 %(2)-------------------------------------------------------------
166 %
167 if indxC0Pres
168 neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur.
169 ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns:
170 % 1st: the jth column (equation) of A+ or A0: f_j or a_j
171 % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
172 % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
173 % 4th: the number s such that f_j(i) = s * a_j(h) holds.
174 %** 1st equation
175 ixmC0Pres{1} = [1 2 2 1
176 1 7 1 1];
177 %** 2nd equation
178 ixmC0Pres{2} = [2 2 2 2];
179 %** 3rd equation
180 ixmC0Pres{3} = [3 7 1 1
181 3 2 2 1];
182
183
184 % % 4 columns.
185 % ncres = 5; % manually key in the number of cross-A0-A+ restrictions
186
187 % % 1st: the jth column (equation) of A+ or A0: f_j or a_j
188 % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
189 % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
190 % % 4th: the number s such that f_j(i) = s * a_j(h) holds.
191 else
192 ixmC0Pres = NaN;
193 end
194