move common dates to parsing function
parent
ee8e8c4282
commit
4dbbdb2c09
|
@ -53,16 +53,8 @@ residnames = cell(neqs, 1);
|
||||||
|
|
||||||
%% Loop over equations
|
%% Loop over equations
|
||||||
for i = 1:neqs
|
for i = 1:neqs
|
||||||
%% Parse equation i
|
[Y{i}, lhssub{i}, X{i}, residnames{i}, startdates{i}, enddates{i}] = ...
|
||||||
[Y{i}, lhssub{i}, X{i}, residnames{i}] = parse_ols_style_equation(ds, ast{i});
|
parse_ols_style_equation(ds, ast{i}, jsonmodel{i});
|
||||||
|
|
||||||
%% Set start and end dates
|
|
||||||
[startdates{i}, enddates{i}] = get_ols_start_end_dates(Y{i}, lhssub{i}, X{i}, jsonmodel{i});
|
|
||||||
Y{i} = Y{i}(startdates{i}:enddates{i});
|
|
||||||
X{i} = X{i}(startdates{i}:enddates{i});
|
|
||||||
if ~isempty(lhssub{i})
|
|
||||||
lhssub{i} = lhssub{i}(startdates{i}:enddates{i});
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if overlapping_dates
|
if overlapping_dates
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
function [fp, lp] = get_ols_start_end_dates(Y, lhssub, X, jsonmodel)
|
|
||||||
% function [fp, lp] = get_ols_start_end_dates(Y, lhssub, X, jsonmodel)
|
|
||||||
% Find the common first observed date and last observed date for X, Y, and
|
|
||||||
% lhssub. Impose sample tag if passed to equation
|
|
||||||
%
|
|
||||||
% INPUTS
|
|
||||||
% Y [cell array] dependent variables
|
|
||||||
% lhssub [cell array] RHS to subtract from Y
|
|
||||||
% X [cell array] regressors
|
|
||||||
% jsonmodel [cell array] JSON representation of model block
|
|
||||||
%
|
|
||||||
% OUTPUTS
|
|
||||||
% fp [date] first observed period
|
|
||||||
% lp [date] last observed period
|
|
||||||
%
|
|
||||||
% 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/>.
|
|
||||||
|
|
||||||
fp = max(Y.firstobservedperiod, X.firstobservedperiod);
|
|
||||||
lp = min(Y.lastobservedperiod, X.lastobservedperiod);
|
|
||||||
if ~isempty(lhssub)
|
|
||||||
fp = max(fp, lhssub.firstobservedperiod);
|
|
||||||
lp = min(lp, lhssub.lastobservedperiod);
|
|
||||||
end
|
|
||||||
if isfield(jsonmodel, 'tags') ...
|
|
||||||
&& isfield(jsonmodel.tags, 'sample') ...
|
|
||||||
&& ~isempty(jsonmodel.tags.sample)
|
|
||||||
colon_idx = strfind(jsonmodel.tags.sample, ':');
|
|
||||||
fsd = dates(jsonmodel.tags.sample(1:colon_idx-1));
|
|
||||||
lsd = dates(jsonmodel.tags.sample(colon_idx+1:end));
|
|
||||||
if fp > fsd
|
|
||||||
warning(['The sample over which you want to estimate contains NaNs. '...
|
|
||||||
'Adjusting estimation range to begin on: ' fp.char])
|
|
||||||
else
|
|
||||||
fp = fsd;
|
|
||||||
end
|
|
||||||
if lp < lsd
|
|
||||||
warning(['The sample over which you want to estimate contains NaNs. '...
|
|
||||||
'Adjusting estimation range to end on: ' lp.char])
|
|
||||||
else
|
|
||||||
lp = lsd;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,4 +1,4 @@
|
||||||
function [Y, lhssub, X, residual] = parse_ols_style_equation(ds, ast)
|
function [Y, lhssub, X, residual, fp, lp] = parse_ols_style_equation(ds, ast, jsonmodel)
|
||||||
%function X = parse_ols_style_equation()
|
%function X = parse_ols_style_equation()
|
||||||
% Run OLS on chosen model equations; unlike olseqs, allow for time t
|
% Run OLS on chosen model equations; unlike olseqs, allow for time t
|
||||||
% endogenous variables on LHS
|
% endogenous variables on LHS
|
||||||
|
@ -6,12 +6,15 @@ function [Y, lhssub, X, residual] = parse_ols_style_equation(ds, ast)
|
||||||
% INPUTS
|
% INPUTS
|
||||||
% ds [dseries] data
|
% ds [dseries] data
|
||||||
% ast [struct] AST representing the equation to be parsed
|
% ast [struct] AST representing the equation to be parsed
|
||||||
|
% jsonmodel [cell array] JSON representation of model block
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% Y [dseries] LHS of the equation (with lhssub subtracted)
|
% Y [dseries] LHS of the equation (with lhssub subtracted)
|
||||||
% lhssub [dseries] RHS subtracted from LHS
|
% lhssub [dseries] RHS subtracted from LHS
|
||||||
% X [dseries] RHS of the equation
|
% X [dseries] RHS of the equation
|
||||||
% residual [string] name of residual in equation
|
% residual [string] name of residual in equation
|
||||||
|
% fp [date] first common observed period between Y, lhssub, and X
|
||||||
|
% lp [date] last common observed period between Y, lhssub, and X
|
||||||
%
|
%
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
@ -33,7 +36,8 @@ function [Y, lhssub, X, residual] = parse_ols_style_equation(ds, ast)
|
||||||
% You should have received a copy of the GNU General Public License
|
% You should have received a copy of the GNU General Public License
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
if nargin ~= 2
|
%% Check inputs
|
||||||
|
if nargin ~= 3
|
||||||
error('parse_ols_style_equation takes 3 arguments')
|
error('parse_ols_style_equation takes 3 arguments')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,8 +45,8 @@ if isempty(ds) || ~isdseries(ds)
|
||||||
error('parse_ols_style_equation: arg 1 must be a dseries');
|
error('parse_ols_style_equation: arg 1 must be a dseries');
|
||||||
end
|
end
|
||||||
|
|
||||||
if ~isstruct(ast) || length(ast) ~= 1
|
if isempty(ast) || ~isstruct(ast)
|
||||||
error('ast must be a celength must be equal to 1');
|
error('ast must be a struct');
|
||||||
end
|
end
|
||||||
|
|
||||||
line = ast.line;
|
line = ast.line;
|
||||||
|
@ -68,11 +72,15 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
% Set LHS (Y)
|
if isempty(jsonmodel) || ~isstruct(jsonmodel)
|
||||||
|
error('jsonmodel must be a struct');
|
||||||
|
end
|
||||||
|
|
||||||
|
%% Set LHS (Y)
|
||||||
lhssub = dseries();
|
lhssub = dseries();
|
||||||
Y = evalNode(ds, ast.AST.arg1, line, dseries());
|
Y = evalNode(ds, ast.AST.arg1, line, dseries());
|
||||||
|
|
||||||
% Set RHS (X)
|
%% Set RHS (X)
|
||||||
plus_node = ast.AST.arg2;
|
plus_node = ast.AST.arg2;
|
||||||
last_node_to_parse = [];
|
last_node_to_parse = [];
|
||||||
residual = '';
|
residual = '';
|
||||||
|
@ -152,6 +160,41 @@ while ~isempty(plus_node) || ~isempty(last_node_to_parse)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Y = Y - lhssub;
|
Y = Y - lhssub;
|
||||||
|
|
||||||
|
%% Set start and end dates
|
||||||
|
fp = max(Y.firstobservedperiod, X.firstobservedperiod);
|
||||||
|
lp = min(Y.lastobservedperiod, X.lastobservedperiod);
|
||||||
|
if ~isempty(lhssub)
|
||||||
|
fp = max(fp, lhssub.firstobservedperiod);
|
||||||
|
lp = min(lp, lhssub.lastobservedperiod);
|
||||||
|
end
|
||||||
|
|
||||||
|
% If it exists, account for tag set in mod file
|
||||||
|
if isfield(jsonmodel, 'tags') ...
|
||||||
|
&& isfield(jsonmodel.tags, 'sample') ...
|
||||||
|
&& ~isempty(jsonmodel.tags.sample)
|
||||||
|
colon_idx = strfind(jsonmodel.tags.sample, ':');
|
||||||
|
fsd = dates(jsonmodel.tags.sample(1:colon_idx-1));
|
||||||
|
lsd = dates(jsonmodel.tags.sample(colon_idx+1:end));
|
||||||
|
if fp > fsd
|
||||||
|
warning(['The sample over which you want to estimate contains NaNs. '...
|
||||||
|
'Adjusting estimation range to begin on: ' fp.char])
|
||||||
|
else
|
||||||
|
fp = fsd;
|
||||||
|
end
|
||||||
|
if lp < lsd
|
||||||
|
warning(['The sample over which you want to estimate contains NaNs. '...
|
||||||
|
'Adjusting estimation range to end on: ' lp.char])
|
||||||
|
else
|
||||||
|
lp = lsd;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Y = Y(fp:lp);
|
||||||
|
X = X(fp:lp);
|
||||||
|
if ~isempty(lhssub)
|
||||||
|
lhssub = lhssub(fp:lp);
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%% Helper Functions
|
%% Helper Functions
|
||||||
|
|
Loading…
Reference in New Issue