Debian Codegraph @

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

raw
1 function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol3v(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 = 2; % 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 -1 0 0
83 0 1 0 0 -1 0
84 0 0 1 0 0 -1
85
86 0 0 0 0 1 0
87 0 0 0 0 0 1
88 ];
89 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
90 for si=1:nStates-1
91 for ki=1:kvar
92 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
93 end
94 end
95 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
96 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
97 Qi(1:nreseqn*nStates,:,eqninx) = [
98 0 1 0 0 0 0
99 0 0 1 0 0 0
100
101 0 0 0 0 1 0
102 0 0 0 0 0 1
103 ];
104
105 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
106 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.
107 for si=1:nStates-1
108 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
109 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
110 end
111 end
112 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
113 for si=1:nStates-1
114 for ki=1:kvar
115 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
116 end
117 end
118 else
119 error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
120 end
121 end
122
123
124 %======== The second equation ===========
125 eqninx = 2;
126 nreseqn = 1; % Number of linear restrictions for A0(:,eqninx) for each state.
127 if (indxEqnTv_m(eqninx, 2)<=2)
128 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
129 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
130 1 0 0 -1 0 0
131 0 1 0 0 -1 0
132 0 0 1 0 0 -1
133
134 0 0 0 0 0 1
135 ];
136 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
137 for si=1:nStates-1
138 for ki=1:kvar
139 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
140 end
141 end
142 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
143 %**** For time-varying A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
144 Qi(1:nreseqn*nStates,:,eqninx) = [
145 0 0 1 0 0 0
146
147 0 0 0 0 0 1
148 ];
149
150 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
151 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.
152 for si=1:nStates-1
153 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
154 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
155 end
156 end
157 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
158 for si=1:nStates-1
159 for ki=1:kvar
160 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
161 end
162 end
163 else
164 error('.../ftd_3s_case3a.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
165 end
166
167 %==== For freely time-varying A+ for only the first 6 lags.
168 %==== Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
169 % nlagsno0 = 6; % Number of lags to be nonzero.
170 % for si=1:nStates
171 % for ki = 1:lags-nlagsno0
172 % for kj=1:nvar
173 % Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
174 % end
175 % end
176 % end
177 %**** 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.
178 % for si=1:nStates-1
179 % for ki=[2*nvar+1:kvar-1]
180 % Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
181 % end
182 % end
183 end
184
185
186 %======== The third equation (money demand) ===========
187 eqninx = 3;
188 nreseqn = 0; % Number of linear restrictions for the equation for each state.
189 if (indxEqnTv_m(eqninx, 2)<=2)
190 %**** For constant A0_s. In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
191 Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
192 1 0 0 -1 0 0
193 0 1 0 0 -1 0
194 0 0 1 0 0 -1
195 ];
196 %**** For constant D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
197 for si=1:nStates-1
198 for ki=1:kvar
199 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
200 end
201 end
202 else % Time-varying equations at least for A0_s. For D+_s, constant-parameter equations in general.
203 %**** For D+_s. In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
204 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.
205 for si=1:nStates-1
206 for ki=1:kvar-1 % -1: no restrictions on the constant term, which is freely time-varying.
207 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
208 end
209 end
210 elseif (indxEqnTv_m(eqninx, 2)==4) % For constant D+**. In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
211 for si=1:nStates-1
212 for ki=1:kvar
213 Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
214 end
215 end
216 else
217 error('.../ftd_2s_caseall_*.m: Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
218 end
219 end
220
221
222
223 for ki=1:nvar % initializing loop for each equation
224 Ui{ki} = null(Qi(:,:,ki));
225 Vi{ki} = null(Ri(:,:,ki));
226 n0(ki) = size(Ui{ki},2);
227 np(ki) = size(Vi{ki},2);
228 end