| 1 |
function [bhat,Vq,ACt,uqhat,q2] = clgls(a,yq,Xq,C,qm,mT,qT) |
| 2 |
%function [bhat,Vq,ACt,uqhat,q2] = clgls(a,yq,Xq,C,qm,mT,qT) |
| 3 |
% bhat = inv[Xq' * inv(Vq) * Xq] * Xq' * inv(Vq) * yq |
| 4 |
% Vq = C*A*C' |
| 5 |
% ACt = A*C' |
| 6 |
% uqhat = yq - Xq * bhat |
| 7 |
% |
| 8 |
% Written by E.M. Leeper |
| 9 |
% Modified by T. Zha, 5/6/97 |
| 10 |
% |
| 11 |
% Copyright (C) 1997-2012 Eric Leeper and Tao Zha |
| 12 |
% |
| 13 |
% This free software: you can redistribute it and/or modify |
| 14 |
% it under the terms of the GNU General Public License as published by |
| 15 |
% the Free Software Foundation, either version 3 of the License, or |
| 16 |
% (at your option) any later version. |
| 17 |
% |
| 18 |
% It is distributed in the hope that it will be useful, |
| 19 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
% GNU General Public License for more details. |
| 22 |
% |
| 23 |
% If you did not received a copy of the GNU General Public License |
| 24 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 25 |
% |
| 26 |
|
| 27 |
|
| 28 |
%*** The following creation of Ahat may be inefficient, T.Z., 5/7/97 |
| 29 |
Ahat = eye(mT,mT); |
| 30 |
i = 1; |
| 31 |
arow = zeros(1,mT-1); |
| 32 |
while i <= mT-1 |
| 33 |
arow(1,i) = a^i; |
| 34 |
i = i + 1; |
| 35 |
end |
| 36 |
i = 1; |
| 37 |
while i <= mT-1 |
| 38 |
Ahat(i,i+1:mT) = arow(1,1:mT-i); |
| 39 |
i = i + 1; |
| 40 |
end |
| 41 |
Ahat = Ahat + Ahat' - eye(mT,mT); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
%*** GLS to estimate bhat |
| 46 |
ACt = Ahat*C'; |
| 47 |
Vq = C*ACt; |
| 48 |
Xqt = Xq'; |
| 49 |
%CACinv = inv(CAhatC); commented out by T.Z., not necessary |
| 50 |
%XqCACinv = Xq' * CACinv; commented out by T.Z., not necessary |
| 51 |
bhat = ((Xqt/Vq)*Xq)\(Xqt*(Vq\yq)); |
| 52 |
uqhat = yq - Xq * bhat; |
| 53 |
|
| 54 |
%*** compute the new quarterly coefficeint "q2" |
| 55 |
uqlag = zeros(qT-1,1); |
| 56 |
uqlag = uqhat(1:qT-1,1); |
| 57 |
uqc = uqhat(2:qT,1); |
| 58 |
[u d v]=svd(uqlag,0); %trial |
| 59 |
dinv = 1./diag(d); % inv(diag(d)) |
| 60 |
vd=v.*(ones(size(v,2),1)*diag(d)'); %trial |
| 61 |
vdinv=v.*(ones(size(v,2),1)*dinv'); %trial |
| 62 |
xtxinv = vdinv*vdinv'; |
| 63 |
uy = u'*uqc; %trial |
| 64 |
xty = vd*uy; %trial |
| 65 |
%Bh = xtx\xty; %inv(X'X)*(X'Y), k*m (ncoe*nvar). |
| 66 |
q2 = xtxinv*xty; % initial q |