Debian Codegraph @

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

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