2019-01-24 12:21:36 +01:00
|
|
|
function [Yvec, lhssubvec, Xmat, constrained] = put_in_sur_form(Y, lhssub, X)
|
|
|
|
%function [Yvec, lhssubvec, Xmat, constrained] = put_in_sur_form(Y, lhssub, X)
|
2019-01-11 11:47:55 +01:00
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% Y [cell array] dependent variables
|
2019-01-24 12:21:36 +01:00
|
|
|
% lhssub [cell array] RHS subtracted from LHS
|
2019-01-11 11:47:55 +01:00
|
|
|
% X [cell array] regressors
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% Yvec [vector] dependent variables
|
2019-01-24 12:21:36 +01:00
|
|
|
% lhssubvec [cell array] RHS subtracted from LHS
|
2019-01-11 11:47:55 +01:00
|
|
|
% Xmat [matrix] regressors
|
|
|
|
% constrained [cellstr] names of parameters that were constrained
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
|
|
|
% Copyright (C) 2019 Dynare Team
|
|
|
|
%
|
|
|
|
% 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/>.
|
|
|
|
|
|
|
|
%% Check inputs
|
2019-01-24 12:21:36 +01:00
|
|
|
if nargin ~= 3
|
|
|
|
error('function expects 3 arguments');
|
2019-01-11 11:47:55 +01:00
|
|
|
end
|
|
|
|
|
2019-01-24 12:21:36 +01:00
|
|
|
if isempty(Y) || ~iscell(Y) ...
|
|
|
|
|| isempty(lhssub) || ~iscell(lhssub) ...
|
|
|
|
|| isempty(X) || ~iscell(X) ...
|
|
|
|
|| length(Y) ~= length(X) ...
|
|
|
|
|| length(Y) ~= length(lhssub)
|
|
|
|
error('function arguments should be cells of the same size');
|
2019-01-11 11:47:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
%% Organize output
|
2019-01-17 15:15:35 +01:00
|
|
|
neqs = length(Y);
|
2019-01-14 14:57:35 +01:00
|
|
|
nobs = zeros(neqs, 1);
|
|
|
|
for i = 1:neqs
|
2019-01-17 15:15:35 +01:00
|
|
|
if ~isempty(X{i})
|
|
|
|
% X{i} is empty for AR(1) equations
|
|
|
|
assert(size(X{i}, 1) == size(Y{i}, 1), 'Y{i} and X{i} must have the same nuber of observations');
|
|
|
|
end
|
2019-01-18 15:07:24 +01:00
|
|
|
nobs(i) = size(Y{i}, 1);
|
2019-01-14 14:57:35 +01:00
|
|
|
end
|
2019-01-18 15:07:24 +01:00
|
|
|
fd = Y{1}.firstdate;
|
2019-01-14 14:57:35 +01:00
|
|
|
nrows = sum(nobs);
|
2019-01-18 15:07:24 +01:00
|
|
|
Xmat = dseries();
|
|
|
|
Yvec = dseries();
|
2019-01-24 12:21:36 +01:00
|
|
|
lhssubvec = dseries();
|
2019-01-11 11:47:55 +01:00
|
|
|
constrained = {};
|
2019-01-18 15:07:24 +01:00
|
|
|
for i = 1:neqs
|
|
|
|
if ~isempty(X{i})
|
2019-01-17 15:15:35 +01:00
|
|
|
to_remove = [];
|
|
|
|
nr = sum(nobs(1:i-1));
|
|
|
|
nxcol = size(X{i}, 2);
|
2019-02-11 16:36:25 +01:00
|
|
|
names = X{i}.name;
|
|
|
|
Xtmp = dseries([zeros(nr, nxcol); X{i}.data; zeros(nrows-nr-nobs(i), nxcol)], fd, names);
|
|
|
|
Xmatnames = Xmat.name;
|
|
|
|
for j = 1:length(names)
|
|
|
|
idx = find(strcmp(Xmatnames, names{j}));
|
2019-01-17 15:15:35 +01:00
|
|
|
if ~isempty(idx)
|
2019-02-11 16:36:25 +01:00
|
|
|
Xmat.(Xmatnames{idx}) = Xmat.(Xmatnames{idx}) + Xtmp.(names{j});
|
|
|
|
Xtmp = Xtmp.remove(names{j});
|
|
|
|
constrained{end+1} = Xmatnames{idx};
|
2019-01-17 15:15:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if ~isempty(Xtmp)
|
|
|
|
Xmat = [Xmat Xtmp];
|
2019-01-11 11:47:55 +01:00
|
|
|
end
|
|
|
|
end
|
2019-01-18 15:07:24 +01:00
|
|
|
Yvec = dseries([Yvec.data; Y{i}.data], fd);
|
2019-01-24 12:21:36 +01:00
|
|
|
if isempty(lhssub{i})
|
|
|
|
lhssubvec = dseries([lhssubvec.data; zeros(size(Y{i}.data, 1), 1)], fd);
|
|
|
|
else
|
|
|
|
lhssubvec = dseries([lhssubvec.data; lhssub{i}.data], fd);
|
|
|
|
end
|
2019-01-11 11:47:55 +01:00
|
|
|
end
|
2019-01-24 11:38:40 +01:00
|
|
|
assert(size(Yvec, 1) == size(Xmat, 1));
|
2019-01-24 12:21:36 +01:00
|
|
|
assert(size(Yvec, 1) == size(lhssubvec, 1));
|
2019-01-11 11:47:55 +01:00
|
|
|
end
|