| 1 |
function [Fmat,gvec] = gfmean(b,P,Vi,nvar,ncoef,n0,np) |
| 2 |
% [Fmat,gvec] = gfmean(b,P,Vi,nvar,ncoef,n0,np) |
| 3 |
% |
| 4 |
% Mean of free lagged parameters g and original lagged parameters F, conditional on comtemporaneous b's |
| 5 |
% See Waggoner and Zha's Gibbs sampling |
| 6 |
% |
| 7 |
% b: sum(n0)-by-1 vector of A0 free parameters |
| 8 |
% P: cell(nvar,1). In each cell, posterior linear transformation for random walk prior for the ith equation % tld: tilda |
| 9 |
% Vi: nvar-by-1 cell. In each cell, k-by-ri orthonormal basis for the null of the ith |
| 10 |
% equation lagged restriction matrix where k is a total of exogenous variables and |
| 11 |
% ri is the number of free parameters. With this transformation, we have fi = Vi*gi |
| 12 |
% or Vi'*fi = gi where fi is a vector of total original parameters and gi is a |
| 13 |
% vector of free parameters. There must be at least one free parameter left for |
| 14 |
% the ith equation. |
| 15 |
% nvar: number of endogeous variables |
| 16 |
% ncoef: number of original lagged variables per equation |
| 17 |
% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation |
| 18 |
% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation |
| 19 |
%--------------- |
| 20 |
% Fmat: 0, the value that is used in csminwel.m |
| 21 |
% gvec: sum(n0)-by-1 analytical gradient for a0freefun.m |
| 22 |
% |
| 23 |
% Tao Zha, February 2000 |
| 24 |
% |
| 25 |
% Copyright (C) 1997-2012 Tao Zha |
| 26 |
% |
| 27 |
% This free software: you can redistribute it and/or modify |
| 28 |
% it under the terms of the GNU General Public License as published by |
| 29 |
% the Free Software Foundation, either version 3 of the License, or |
| 30 |
% (at your option) any later version. |
| 31 |
% |
| 32 |
% It is distributed in the hope that it will be useful, |
| 33 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 34 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 35 |
% GNU General Public License for more details. |
| 36 |
% |
| 37 |
% If you did not received a copy of the GNU General Public License |
| 38 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 39 |
% |
| 40 |
|
| 41 |
|
| 42 |
b=b(:); |
| 43 |
|
| 44 |
|
| 45 |
n0cum = cumsum(n0); |
| 46 |
npcum = cumsum(np); |
| 47 |
gvec = zeros(npcum(end),1); |
| 48 |
Fmat = zeros(ncoef,nvar); % ncoef: maximum original lagged parameters per equation |
| 49 |
|
| 50 |
if ~(length(b)==n0cum(end)) |
| 51 |
error('Make inputs n0 and length(b) match exactly') |
| 52 |
end |
| 53 |
|
| 54 |
for kj=1:nvar |
| 55 |
if kj==1 |
| 56 |
bj = b(1:n0(kj)); |
| 57 |
gj = P{kj}*bj; |
| 58 |
gvec(1:np(kj)) = gj; |
| 59 |
Fmat(:,kj) = Vi{kj}*gj; |
| 60 |
else |
| 61 |
bj = b(n0cum(kj-1)+1:n0cum(kj)); |
| 62 |
gj = P{kj}*bj; |
| 63 |
gvec(npcum(kj-1)+1:npcum(kj)) = gj; |
| 64 |
Fmat(:,kj) = Vi{kj}*gj; |
| 65 |
end |
| 66 |
end |