dynare/matlab/ols/common_parsing.m

72 lines
2.5 KiB
Matlab
Raw Normal View History

2019-01-14 15:43:29 +01:00
function [Y, lhssub, X, startdates, enddates, residnames] = common_parsing(ds, ast, jsonmodel, overlapping_dates)
%function [Y, lhssub, X, startdates, enddates, residnames] = common_parsing(ds, ast, jsonmodel, overlapping_dates)
%
% Code common to sur.m and pooled_ols.m
%
% INPUTS
2017-12-13 12:29:42 +01:00
% ds [dseries] dataset
2019-01-11 11:26:13 +01:00
% ast [cell array] JSON representation of abstract syntax tree
2018-01-19 14:41:28 +01:00
% jsonmodel [cell array] JSON representation of model block
% overlapping_dates [boolean] if true, dates are same across equations
%
% OUTPUTS
2019-01-11 11:26:13 +01:00
% Y [cell array] dependent variables
% lhssub [cell array] RHS to subtract from Y
% X [cell array] regressors
2018-01-19 14:41:28 +01:00
% startdates [cell array] first observed period for each
2017-12-13 12:29:42 +01:00
% equation
2018-01-19 14:41:28 +01:00
% enddates [cell array] last observed period for each
2017-12-13 12:29:42 +01:00
% equation
% startidxs [vector] rows corresponding to each
% equation's observations
2018-01-19 14:41:28 +01:00
% residnames [cell array] name of residual in each equation
%
% SPECIAL REQUIREMENTS
% none
2019-01-11 11:26:13 +01:00
% 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/>.
2019-01-11 11:26:13 +01:00
%% Initialize variables
2019-01-15 11:05:55 +01:00
neqs = length(ast);
Y = cell(neqs, 1);
lhssub = cell(neqs, 1);
X = cell(neqs, 1);
startdates = cell(neqs, 1);
enddates = cell(neqs, 1);
residnames = cell(neqs, 1);
2019-01-11 11:26:13 +01:00
%% Loop over equations
for i = 1:neqs
2019-01-15 11:06:31 +01:00
[Y{i}, lhssub{i}, X{i}, residnames{i}, startdates{i}, enddates{i}] = ...
parse_ols_style_equation(ds, ast{i}, jsonmodel{i});
2019-01-11 11:26:13 +01:00
end
if overlapping_dates
maxfp = max([startdates{:}]);
minlp = min([enddates{:}]);
for i = 1:neqs
Y{i} = Y{i}(maxfp:minlp);
X{i} = X{i}(maxfp:minlp);
if ~isempty(lhssub{i})
lhssub{i} = lhssub{i}(maxfp:minlp);
end
end
end
end