Debian Codegraph @

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

raw
1 function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol7v(lags,nvar,nStates,indxEqnTv_m,nexo)
2 % Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
3 % All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
4 % of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
5 %
6 % Variables: Pcom, M2, FFR, y, P, U. Equations: information, policy, money demand, y, P, U.
7 % Exporting orthonormal matrices for the deterministic linear restrictions
8 % (equation by equation) with time-varying A0 and D+** equations.
9 % See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
10 %
11 % lags: Maximum length of lag.
12 % nvar: Number of endogeous variables.
13 % nStates: Number of states.
14 % indxEqnTv_m: nvar-by-2. Stores equation characteristics.
15 % 1st column: labels of equations [1:nvar]'.
16 % 2nd column: labels of time-varying features with
17 % 1: indxConst -- all coefficients are constant,
18 % 2: indxStv -- only shocks are time-varying,
19 % 3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
20 % 4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
21 % 5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
22 % nexo: number of exogenous variables. If nexo is not supplied, nexo=1 as default for a constant.
23 % So far this function is written to handle one exogenous variable, which is a constant term.
24 %-----------------
25 % Ui: nvar-by-1 cell. In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
26 % equation contemporaneous restriction matrix where qi is the number of free parameters
27 % within the state and si is the number of free states.
28 % With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
29 % of total original parameters and bi is a vector of free parameters. When no
30 % restrictions are imposed, we have Ui = I. There must be at least one free
31 % parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
32 % Vi: nvar-by-1 cell. In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
33 % equation lagged restriction matrix where k is a total of exogenous variables and
34 % ri is the number of free parameters within the state and si is the number of free states.
35 % With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
36 % parameters and gi is a vector of free parameters. The ith equation is in the order of [nvar variables
37 % for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
38 % variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
39 % n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
40 % np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
41 %
42 % Tao Zha, February 2003
43
44
45
46 Ui = cell(nvar,1); % initializing for contemporaneous endogenous variables
47 Vi = cell(nvar,1); % initializing for lagged and exogenous variables
48 n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
49 np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
50
51 if (nargin==3)
52 nexo = 1; % 1: constant as default where nexo must be a nonnegative integer
53 end
54
55
56 n = nvar*nStates;
57 kvar=lags*nvar+nexo; % Maximum number of lagged and exogenous variables in each equation under each state.
58 k = kvar*nStates; % Maximum number of lagged and exogenous variables in each equation in all states.
59
60 Qi = zeros(n,n,nvar); % 3rd dim: nvar contemporaneous equations.
61 Ri = zeros(k,k,nvar); % 1st and 2nd dims: lagged and exogenous equations.
62 % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
63 % 0 means no restriction.
64 % 1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
65 % 1 (only 1) means that the corresponding parameter is restricted to 0.
66
67 %nfvar = 6; % number of foreign (Granger causing) variables
68 %nhvar = nvar-nfvar; % number of home (affected) variables.
69
70
71 %-------------------------------------------------------------
72 % Beginning the manual input of the restrictions one quation at a time for A0_s.
73 %-------------------------------------------------------------
74 %
75
76 %======== The first equation ===========
77 eqninx = 1;
78 nreseqn = 6; % Number of linear restrictions for A0(:,eqninx) for each state.
79 if (indxEqnTv_m(eqninx, 2)<=2)
80 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
81 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
82 1 0 0 0 0 0 0 -1 0 0 0 0 0 0
83 0 1 0 0 0 0 0 0 -1 0 0 0 0 0
84 0 0 1 0 0 0 0 0 0 -1 0 0 0 0
85 0 0 0 1 0 0 0 0 0 0 -1 0 0 0
86 0 0 0 0 1 0 0 0 0 0 0 -1 0 0
87 0 0 0 0 0 1 0 0 0 0 0 0 -1 0
88 0 0 0 0 0 0 1 0 0 0 0 0 0 -1
89
90 0 0 0 0 0 0 0 0 1 0 0 0 0 0
91 0 0 0 0 0 0 0 0 0 1 0 0 0 0
92 0 0 0 0 0 0 0 0 0 0 1 0 0 0
93 0 0 0 0 0 0 0 0 0 0 0 1 0 0
94 0 0 0 0 0 0 0 0 0 0 0 0 1 0
95 0 0 0 0 0 0 0 0 0 0 0 0 0 1
96 ];
97 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
98 for si=1:nStates-1
99 for ki=1:kvar
100 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
101 end
102 end
103 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
104 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
105 Qi(1:nreseqn*nStates,:,eqninx) = [
106 0 1 0 0 0 0 0 0 0 0 0 0 0 0
107 0 0 1 0 0 0 0 0 0 0 0 0 0 0
108 0 0 0 1 0 0 0 0 0 0 0 0 0 0
109 0 0 0 0 1 0 0 0 0 0 0 0 0 0
110 0 0 0 0 0 1 0 0 0 0 0 0 0 0
111 0 0 0 0 0 0 1 0 0 0 0 0 0 0
112
113 0 0 0 0 0 0 0 0 1 0 0 0 0 0
114 0 0 0 0 0 0 0 0 0 1 0 0 0 0
115 0 0 0 0 0 0 0 0 0 0 1 0 0 0
116 0 0 0 0 0 0 0 0 0 0 0 1 0 0
117 0 0 0 0 0 0 0 0 0 0 0 0 1 0
118 0 0 0 0 0 0 0 0 0 0 0 0 0 1
119 ];
120
121 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
122 if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
123 for si=1:nStates-1
124 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
125 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
126 end
127 end
128 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
129 for si=1:nStates-1
130 for ki=1:kvar
131 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
132 end
133 end
134 else
135 error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
136 end
137 end
138
139
140 %======== The second equation ===========
141 eqninx = 2;
142 nreseqn = 5; % Number of linear restrictions for A0(:,eqninx) for each state.
143 if (indxEqnTv_m(eqninx, 2)<=2)
144 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
145 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
146 1 0 0 0 0 0 0 -1 0 0 0 0 0 0
147 0 1 0 0 0 0 0 0 -1 0 0 0 0 0
148 0 0 1 0 0 0 0 0 0 -1 0 0 0 0
149 0 0 0 1 0 0 0 0 0 0 -1 0 0 0
150 0 0 0 0 1 0 0 0 0 0 0 -1 0 0
151 0 0 0 0 0 1 0 0 0 0 0 0 -1 0
152 0 0 0 0 0 0 1 0 0 0 0 0 0 -1
153
154 0 0 0 0 0 0 0 0 0 1 0 0 0 0
155 0 0 0 0 0 0 0 0 0 0 1 0 0 0
156 0 0 0 0 0 0 0 0 0 0 0 1 0 0
157 0 0 0 0 0 0 0 0 0 0 0 0 1 0
158 0 0 0 0 0 0 0 0 0 0 0 0 0 1
159 ];
160 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
161 for si=1:nStates-1
162 for ki=1:kvar
163 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
164 end
165 end
166 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
167 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
168 Qi(1:nreseqn*nStates,:,eqninx) = [
169 0 0 1 0 0 0 0 0 0 0 0 0 0 0
170 0 0 0 1 0 0 0 0 0 0 0 0 0 0
171 0 0 0 0 1 0 0 0 0 0 0 0 0 0
172 0 0 0 0 0 1 0 0 0 0 0 0 0 0
173 0 0 0 0 0 0 1 0 0 0 0 0 0 0
174
175 0 0 0 0 0 0 0 0 0 1 0 0 0 0
176 0 0 0 0 0 0 0 0 0 0 1 0 0 0
177 0 0 0 0 0 0 0 0 0 0 0 1 0 0
178 0 0 0 0 0 0 0 0 0 0 0 0 1 0
179 0 0 0 0 0 0 0 0 0 0 0 0 0 1
180 ];
181
182 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
183 if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
184 for si=1:nStates-1
185 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
186 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
187 end
188 end
189 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
190 for si=1:nStates-1
191 for ki=1:kvar
192 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
193 end
194 end
195 else
196 error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
197 end
198 end
199
200
201 %======== The third equation ===========
202 eqninx = 3;
203 nreseqn = 4; % Number of linear restrictions for A0(:,eqninx) for each state.
204 if (indxEqnTv_m(eqninx, 2)<=2)
205 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
206 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
207 1 0 0 0 0 0 0 -1 0 0 0 0 0 0
208 0 1 0 0 0 0 0 0 -1 0 0 0 0 0
209 0 0 1 0 0 0 0 0 0 -1 0 0 0 0
210 0 0 0 1 0 0 0 0 0 0 -1 0 0 0
211 0 0 0 0 1 0 0 0 0 0 0 -1 0 0
212 0 0 0 0 0 1 0 0 0 0 0 0 -1 0
213 0 0 0 0 0 0 1 0 0 0 0 0 0 -1
214
215 0 0 0 0 0 0 0 0 0 0 1 0 0 0
216 0 0 0 0 0 0 0 0 0 0 0 1 0 0
217 0 0 0 0 0 0 0 0 0 0 0 0 1 0
218 0 0 0 0 0 0 0 0 0 0 0 0 0 1
219 ];
220 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
221 for si=1:nStates-1
222 for ki=1:kvar
223 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
224 end
225 end
226 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
227 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
228 Qi(1:nreseqn*nStates,:,eqninx) = [
229 0 0 0 1 0 0 0 0 0 0 0 0 0 0
230 0 0 0 0 1 0 0 0 0 0 0 0 0 0
231 0 0 0 0 0 1 0 0 0 0 0 0 0 0
232 0 0 0 0 0 0 1 0 0 0 0 0 0 0
233
234 0 0 0 0 0 0 0 0 0 0 1 0 0 0
235 0 0 0 0 0 0 0 0 0 0 0 1 0 0
236 0 0 0 0 0 0 0 0 0 0 0 0 1 0
237 0 0 0 0 0 0 0 0 0 0 0 0 0 1
238 ];
239
240 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
241 if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
242 for si=1:nStates-1
243 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
244 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
245 end
246 end
247 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
248 for si=1:nStates-1
249 for ki=1:kvar
250 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
251 end
252 end
253 else
254 error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
255 end
256 end
257
258
259
260 %======== The fourth equation ===========
261 eqninx = 4;
262 nreseqn = 3; % Number of linear restrictions for A0(:,eqninx) for each state.
263 if (indxEqnTv_m(eqninx, 2)<=2)
264 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
265 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
266 1 0 0 0 0 0 0 -1 0 0 0 0 0 0
267 0 1 0 0 0 0 0 0 -1 0 0 0 0 0
268 0 0 1 0 0 0 0 0 0 -1 0 0 0 0
269 0 0 0 1 0 0 0 0 0 0 -1 0 0 0
270 0 0 0 0 1 0 0 0 0 0 0 -1 0 0
271 0 0 0 0 0 1 0 0 0 0 0 0 -1 0
272 0 0 0 0 0 0 1 0 0 0 0 0 0 -1
273
274 0 0 0 0 0 0 0 0 0 0 0 1 0 0
275 0 0 0 0 0 0 0 0 0 0 0 0 1 0
276 0 0 0 0 0 0 0 0 0 0 0 0 0 1
277 ];
278 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
279 for si=1:nStates-1
280 for ki=1:kvar
281 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
282 end
283 end
284 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
285 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
286 Qi(1:nreseqn*nStates,:,eqninx) = [
287 0 0 0 0 1 0 0 0 0 0 0 0 0 0
288 0 0 0 0 0 1 0 0 0 0 0 0 0 0
289 0 0 0 0 0 0 1 0 0 0 0 0 0 0
290
291 0 0 0 0 0 0 0 0 0 0 0 1 0 0
292 0 0 0 0 0 0 0 0 0 0 0 0 1 0
293 0 0 0 0 0 0 0 0 0 0 0 0 0 1
294 ];
295
296 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
297 if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
298 for si=1:nStates-1
299 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
300 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
301 end
302 end
303 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
304 for si=1:nStates-1
305 for ki=1:kvar
306 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
307 end
308 end
309 else
310 error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
311 end
312
313 %==== For freely time-varying A+ for only the first 6 lags.
314 %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
315 % nlagsno0 = 6; % Number of lags to be nonzero.
316 % for si=1:nStates
317 % for ki = 1:lags-nlagsno0
318 % for kj=1:nvar
319 % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
320 % end
321 % end
322 % end
323 %**** For constant D+_s except the first two lags and the constant term. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
324 % for si=1:nStates-1
325 % for ki=[2*nvar+1:kvar-1]
326 % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
327 % end
328 % end
329 end
330
331
332 %======== The fifth equation ===========
333 eqninx = 5;
334 nreseqn = 2; % Number of linear restrictions for the equation for each state.
335 if (indxEqnTv_m(eqninx, 2)<=2)
336 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
337 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
338 1 0 0 0 0 0 0 -1 0 0 0 0 0 0
339 0 1 0 0 0 0 0 0 -1 0 0 0 0 0
340 0 0 1 0 0 0 0 0 0 -1 0 0 0 0
341 0 0 0 1 0 0 0 0 0 0 -1 0 0 0
342 0 0 0 0 1 0 0 0 0 0 0 -1 0 0
343 0 0 0 0 0 1 0 0 0 0 0 0 -1 0
344 0 0 0 0 0 0 1 0 0 0 0 0 0 -1
345
346 0 0 0 0 0 0 0 0 0 0 0 0 1 0
347 0 0 0 0 0 0 0 0 0 0 0 0 0 1
348 ];
349 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
350 for si=1:nStates-1
351 for ki=1:kvar
352 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
353 end
354 end
355 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
356 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
357 Qi(1:nreseqn*nStates,:,eqninx) = [
358 0 0 0 0 0 1 0 0 0 0 0 0 0 0
359 0 0 0 0 0 0 1 0 0 0 0 0 0 0
360
361 0 0 0 0 0 0 0 0 0 0 0 0 1 0
362 0 0 0 0 0 0 0 0 0 0 0 0 0 1
363 ];
364 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
365 if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
366 for si=1:nStates-1
367 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
368 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
369 end
370 end
371 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
372 for si=1:nStates-1
373 for ki=1:kvar
374 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
375 end
376 end
377 else
378 error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
379 end
380 end
381
382
383 %======== The sixth equation ===========
384 eqninx = 6;
385 nreseqn = 1; % Number of linear restrictions for the equation for each state.
386 if (indxEqnTv_m(eqninx, 2)<=2)
387 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
388 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
389 1 0 0 0 0 0 0 -1 0 0 0 0 0 0
390 0 1 0 0 0 0 0 0 -1 0 0 0 0 0
391 0 0 1 0 0 0 0 0 0 -1 0 0 0 0
392 0 0 0 1 0 0 0 0 0 0 -1 0 0 0
393 0 0 0 0 1 0 0 0 0 0 0 -1 0 0
394 0 0 0 0 0 1 0 0 0 0 0 0 -1 0
395 0 0 0 0 0 0 1 0 0 0 0 0 0 -1
396
397 0 0 0 0 0 0 0 0 0 0 0 0 0 1
398 ];
399 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
400 for si=1:nStates-1
401 for ki=1:kvar
402 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
403 end
404 end
405 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
406 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
407 Qi(1:nreseqn*nStates,:,eqninx) = [
408 0 0 0 0 0 0 1 0 0 0 0 0 0 0
409
410 0 0 0 0 0 0 0 0 0 0 0 0 0 1
411 ];
412 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
413 if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
414 for si=1:nStates-1
415 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
416 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
417 end
418 end
419 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
420 for si=1:nStates-1
421 for ki=1:kvar
422 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
423 end
424 end
425 else
426 error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
427 end
428 end
429
430
431 %======== The seventh equation ===========
432 eqninx = 7;
433 nreseqn = 0; % Number of linear restrictions for the equation for each state.
434 if (indxEqnTv_m(eqninx, 2)<=2)
435 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
436 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
437 1 0 0 0 0 0 0 -1 0 0 0 0 0 0
438 0 1 0 0 0 0 0 0 -1 0 0 0 0 0
439 0 0 1 0 0 0 0 0 0 -1 0 0 0 0
440 0 0 0 1 0 0 0 0 0 0 -1 0 0 0
441 0 0 0 0 1 0 0 0 0 0 0 -1 0 0
442 0 0 0 0 0 1 0 0 0 0 0 0 -1 0
443 0 0 0 0 0 0 1 0 0 0 0 0 0 -1
444 ];
445 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
446 for si=1:nStates-1
447 for ki=1:kvar
448 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
449 end
450 end
451 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
452 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
453 if (indxEqnTv_m(eqninx, 2)==3) % For constant D+** except the constant term. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
454 for si=1:nStates-1
455 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
456 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
457 end
458 end
459 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
460 for si=1:nStates-1
461 for ki=1:kvar
462 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
463 end
464 end
465 else
466 error('.../ftd_2s_caseall_simszha5v.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
467 end
468 end
469
470
471
472
473
474 %===== Lagged restrictions in foreign (Granger causing) block
475 %nfbres = lags*(nvar-nfvar); % number of block restrictions in each foreign equation
476 %bfor = zeros(nfbres,k); % each foreign equation
477 %cnt=0;
478 %for ki = 1:lags
479 % for kj=1:nvar-nfvar
480 % cnt=cnt+1;
481 % bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
482 % end
483 %end
484 %%
485 %if cnt~=nfbres
486 % error('Check lagged restrictions in foreign equations!')
487 %end
488 %%
489 %for kj=1:nfvar
490 % Ri(1:nfbres,:,kj) = bfor;
491 %end
492
493
494 %===== Lagged restrictions in home (affected) block
495 %
496 %~~~~~ selected domestic equations
497 %dlrindx = nfvar+1; %[nfvar+1 nfvar+2]; % index for relevant home equations
498 %rfvindx = []; %[6]; %[1 2 3 5]; % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
499 %%nf2hvar = nfvar-length(rfvindx); % number of free parameters -- foreign variables entering the home sector
500 %nhbres = lags*length(rfvindx); % number of block restrictions in each home equation
501 %bhom = zeros(nhbres,k); % each home equation
502 %cnt=0;
503 %for ki = 1:lags
504 % for kj=1:length(rfvindx)
505 % cnt=cnt+1;
506 % bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
507 % end
508 %end
509 %%
510 %if cnt~=nhbres
511 % error('Check lagged restrictions in domestic equations!')
512 %end
513 %%
514 %for kj=dlrindx
515 % Ri(1:nhbres,:,kj) = bhom;
516 %end
517
518
519
520 for ki=1:nvar % initializing loop for each equation
521 Ui{ki} = null(Qi(:,:,ki));
522 Vi{ki} = null(Ri(:,:,ki));
523 n0(ki) = size(Ui{ki},2);
524 np(ki) = size(Vi{ki},2);
525 end