2018-01-17 11:56:47 +01:00
|
|
|
function pooled_fgls(ds, param_common, param_regex, eqtags)
|
|
|
|
% function pooled_fgls(ds, param_common, param_regex, eqtags)
|
2017-11-15 12:36:12 +01:00
|
|
|
% Run Pooled FGLS
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% ds [dseries] data to use in estimation
|
|
|
|
% param_common [cellstr] List of values to insert into param_regex,
|
|
|
|
% e.g. country codes {'FR', 'DE', 'IT'}
|
|
|
|
% param_regex [cellstr] Where '*' should be replaced by the first
|
|
|
|
% value in param_common
|
2018-01-17 11:56:47 +01:00
|
|
|
% eqtags [cellstr] names of equation tags to estimate. If empty,
|
|
|
|
% estimate all equations
|
2017-11-15 12:36:12 +01:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
2019-01-22 16:11:03 +01:00
|
|
|
% dynare must have been run with the option: json=parse
|
2017-11-15 12:36:12 +01:00
|
|
|
|
2019-01-14 16:42:57 +01:00
|
|
|
% Copyright (C) 2017-2019 Dynare Team
|
2017-11-15 12:36:12 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
global M_ oo_
|
|
|
|
|
2019-01-14 16:42:57 +01:00
|
|
|
%% Check input arguments
|
|
|
|
|
2018-01-17 11:56:47 +01:00
|
|
|
if nargin < 4
|
2019-01-14 16:42:57 +01:00
|
|
|
eqtags = {};
|
2018-01-17 11:56:47 +01:00
|
|
|
end
|
2017-11-15 12:36:12 +01:00
|
|
|
|
2019-01-14 16:42:57 +01:00
|
|
|
pooled_ols(ds, param_common, param_regex, true, eqtags);
|
|
|
|
|
|
|
|
oo_.pooled_fgls.dof = size(oo_.pooled_fgls.X,1)/length(oo_.pooled_fgls.residnames);
|
2017-11-17 12:30:32 +01:00
|
|
|
resid = oo_.pooled_fgls.Y - oo_.pooled_fgls.X * oo_.pooled_fgls.beta;
|
2019-01-14 16:42:57 +01:00
|
|
|
resid = reshape(resid, oo_.pooled_fgls.dof, length(oo_.pooled_fgls.residnames));
|
|
|
|
M_.Sigma_e = resid'*resid/oo_.pooled_fgls.dof;
|
2017-11-15 12:36:12 +01:00
|
|
|
|
2019-01-14 16:42:57 +01:00
|
|
|
kLeye = kron(chol(inv(M_.Sigma_e)), eye(oo_.pooled_fgls.dof));
|
2017-11-15 12:36:12 +01:00
|
|
|
[q, r] = qr(kLeye*oo_.pooled_fgls.X, 0);
|
|
|
|
oo_.pooled_fgls.beta = r\(q'*kLeye*oo_.pooled_fgls.Y);
|
|
|
|
|
|
|
|
regexcountries = ['(' strjoin(param_common(1:end),'|') ')'];
|
|
|
|
pbeta = oo_.pooled_fgls.pbeta;
|
|
|
|
assigned_idxs = false(size(pbeta));
|
|
|
|
for i = 1:length(param_regex)
|
|
|
|
beta_idx = strcmp(pbeta, strrep(param_regex{i}, '*', oo_.pooled_fgls.country_name));
|
|
|
|
assigned_idxs = assigned_idxs | beta_idx;
|
|
|
|
value = oo_.pooled_fgls.beta(beta_idx);
|
2018-01-19 12:51:51 +01:00
|
|
|
if isempty(eqtags)
|
|
|
|
assert(~isempty(value));
|
|
|
|
end
|
|
|
|
if ~isempty(value)
|
|
|
|
M_.params(~cellfun(@isempty, regexp(M_.param_names, ...
|
|
|
|
strrep(param_regex{i}, '*', regexcountries)))) = value;
|
|
|
|
end
|
2017-11-15 12:36:12 +01:00
|
|
|
end
|
|
|
|
idxs = find(assigned_idxs == 0);
|
|
|
|
values = oo_.pooled_fgls.beta(idxs);
|
|
|
|
names = pbeta(idxs);
|
2018-01-19 12:51:51 +01:00
|
|
|
assert(length(values) == length(names));
|
2017-11-15 12:36:12 +01:00
|
|
|
for i = 1:length(idxs)
|
2018-01-11 17:10:12 +01:00
|
|
|
M_.params(strcmp(M_.param_names, names{i})) = values(i);
|
2017-11-15 12:36:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
oo_.pooled_fgls = rmfield(oo_.pooled_fgls, 'X');
|
|
|
|
oo_.pooled_fgls = rmfield(oo_.pooled_fgls, 'Y');
|
|
|
|
oo_.pooled_fgls = rmfield(oo_.pooled_fgls, 'residnames');
|
|
|
|
oo_.pooled_fgls = rmfield(oo_.pooled_fgls, 'pbeta');
|
|
|
|
oo_.pooled_fgls = rmfield(oo_.pooled_fgls, 'country_name');
|
|
|
|
|
|
|
|
end
|