Debian Codegraph @

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

raw
1 function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol7v(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:6,:,1) = [
70 0 1 0 0 0 0 0
71 0 0 1 0 0 0 0
72 0 0 0 1 0 0 0
73 0 0 0 0 1 0 0
74 0 0 0 0 0 1 0
75 0 0 0 0 0 0 1
76 ];
77
78 %======== The second equation ===========
79 Qi(1:5,:,2) = [
80 0 0 1 0 0 0 0
81 0 0 0 1 0 0 0
82 0 0 0 0 1 0 0
83 0 0 0 0 0 1 0
84 0 0 0 0 0 0 1
85 ];
86
87 %======== The third equation ===========
88 Qi(1:4,:,3) = [
89 0 0 0 1 0 0 0
90 0 0 0 0 1 0 0
91 0 0 0 0 0 1 0
92 0 0 0 0 0 0 1
93 ];
94
95 %======== The fourth equation ===========
96 Qi(1:3,:,4) = [
97 0 0 0 0 1 0 0
98 0 0 0 0 0 1 0
99 0 0 0 0 0 0 1
100 ];
101
102
103 %======== The fifth equation ===========
104 Qi(1:2,:,5) = [
105 0 0 0 0 0 1 0
106 0 0 0 0 0 0 1
107 ];
108
109
110 %======== The sixth equation ===========
111 Qi(1:1,:,6) = [
112 0 0 0 0 0 0 1
113 ];
114
115
116 %======== The seventh equation ===========
117
118 %===== Lagged restrictions in foreign (Granger causing) block
119 %nfbres = lags*(nvar-nfvar); % number of block restrictions in each foreign equation
120 %bfor = zeros(nfbres,k); % each foreign equation
121 %cnt=0;
122 %for ki = 1:lags
123 % for kj=1:nvar-nfvar
124 % cnt=cnt+1;
125 % bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
126 % end
127 %end
128 %%
129 %if cnt~=nfbres
130 % error('Check lagged restrictions in foreign equations!')
131 %end
132 %%
133 %for kj=1:nfvar
134 % Ri(1:nfbres,:,kj) = bfor;
135 %end
136
137
138 %===== Lagged restrictions in home (affected) block
139 %
140 %~~~~~ selected domestic equations
141 %dlrindx = nfvar+1; %[nfvar+1 nfvar+2]; % index for relevant home equations
142 %rfvindx = []; %[6]; %[1 2 3 5]; % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
143 %%nf2hvar = nfvar-length(rfvindx); % number of free parameters -- foreign variables entering the home sector
144 %nhbres = lags*length(rfvindx); % number of block restrictions in each home equation
145 %bhom = zeros(nhbres,k); % each home equation
146 %cnt=0;
147 %for ki = 1:lags
148 % for kj=1:length(rfvindx)
149 % cnt=cnt+1;
150 % bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
151 % end
152 %end
153 %%
154 %if cnt~=nhbres
155 % error('Check lagged restrictions in domestic equations!')
156 %end
157 %%
158 %for kj=dlrindx
159 % Ri(1:nhbres,:,kj) = bhom;
160 %end
161
162
163 for n=1:nvar % initializing loop for each equation
164 Ui{n} = null(Qi(:,:,n));
165 Vi{n} = null(Ri(:,:,n));
166 n0(n) = size(Ui{n},2);
167 np(n) = size(Vi{n},2);
168 end
169
170
171
172 %(2)-------------------------------------------------------------
173 % Cross-A0-and-A+ rerestrictions one quation at a time
174 % i.e., the first, second, ..., kjth, ..., equation
175 %(2)-------------------------------------------------------------
176 %
177 if indxC0Pres
178 neq_cres = 3; % the number of equations in which cross-A0-A+ restrictions occur.
179 ixmC0Pres = cell(neq_cres,1); % in each cell representing equation, we have 4 columns:
180 % 1st: the jth column (equation) of A+ or A0: f_j or a_j
181 % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
182 % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
183 % 4th: the number s such that f_j(i) = s * a_j(h) holds.
184 %** 1st equation
185 ixmC0Pres{1} = [1 2 2 1
186 1 7 1 1];
187 %** 2nd equation
188 ixmC0Pres{2} = [2 2 2 2];
189 %** 3rd equation
190 ixmC0Pres{3} = [3 7 1 1
191 3 2 2 1];
192
193
194 % % 4 columns.
195 % ncres = 5; % manually key in the number of cross-A0-A+ restrictions
196
197 % % 1st: the jth column (equation) of A+ or A0: f_j or a_j
198 % % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
199 % % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
200 % % 4th: the number s such that f_j(i) = s * a_j(h) holds.
201 else
202 ixmC0Pres = NaN;
203 end
204