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