sur, pooled_fgls, pooled_ols: add date range option
parent
4dbbf4f02e
commit
825a010a90
|
@ -1,5 +1,5 @@
|
||||||
function pooled_fgls(ds, param_common, param_regex, eqtags, model_name, param_names)
|
function pooled_fgls(ds, param_common, param_regex, eqtags, model_name, param_names, ds_range)
|
||||||
% function pooled_fgls(ds, param_common, param_regex, eqtags, model_name, param_names)
|
% function pooled_fgls(ds, param_common, param_regex, eqtags, model_name, param_names, ds_range)
|
||||||
% Run Pooled FGLS
|
% Run Pooled FGLS
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
|
@ -15,6 +15,8 @@ function pooled_fgls(ds, param_common, param_regex, eqtags, model_name, param_na
|
||||||
% param_names [cellstr] list of parameters to estimate (if
|
% param_names [cellstr] list of parameters to estimate (if
|
||||||
% empty, estimate all) (may contain regex
|
% empty, estimate all) (may contain regex
|
||||||
% to match param_regex)
|
% to match param_regex)
|
||||||
|
% ds_range [dates] range of dates to use in estimation
|
||||||
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% none
|
% none
|
||||||
%
|
%
|
||||||
|
@ -41,10 +43,18 @@ function pooled_fgls(ds, param_common, param_regex, eqtags, model_name, param_na
|
||||||
global M_ oo_
|
global M_ oo_
|
||||||
|
|
||||||
%% Check input arguments
|
%% Check input arguments
|
||||||
if nargin < 1 || nargin > 6
|
if nargin < 1 || nargin > 7
|
||||||
error('Incorrect number of arguments')
|
error('Incorrect number of arguments')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if isempty(ds) || ~isdseries(ds)
|
||||||
|
error('The first argument must be a dseries');
|
||||||
|
end
|
||||||
|
|
||||||
|
if nargin < 7
|
||||||
|
ds_range = ds.dates;
|
||||||
|
end
|
||||||
|
|
||||||
if nargin < 6
|
if nargin < 6
|
||||||
param_names = {};
|
param_names = {};
|
||||||
end
|
end
|
||||||
|
@ -61,7 +71,7 @@ maxit = 100;
|
||||||
tol = 1e-6;
|
tol = 1e-6;
|
||||||
|
|
||||||
%% Common work between pooled_ols and pooled_fgls
|
%% Common work between pooled_ols and pooled_fgls
|
||||||
[Y, X, pbeta, residnames, country_name, model_name] = pooled_ols(ds, param_common, param_regex, true, eqtags, model_name, param_names);
|
[Y, X, pbeta, residnames, country_name, model_name] = pooled_ols(ds, param_common, param_regex, true, eqtags, model_name, param_names, ds_range);
|
||||||
|
|
||||||
%% Estimation
|
%% Estimation
|
||||||
neqs = length(residnames);
|
neqs = length(residnames);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function varargout = pooled_ols(ds, param_common, param_regex, overlapping_dates, eqtags, model_name, param_names)
|
function varargout = pooled_ols(ds, param_common, param_regex, overlapping_dates, eqtags, model_name, param_names, ds_range)
|
||||||
% function varargout = pooled_ols(ds, param_common, param_regex, overlapping_dates, eqtags, model_name, param_names)
|
% function varargout = pooled_ols(ds, param_common, param_regex, overlapping_dates, eqtags, model_name, param_names, ds_range)
|
||||||
% Run Pooled OLS
|
% Run Pooled OLS
|
||||||
% Apply parameter values found to corresponding parameter values in the
|
% Apply parameter values found to corresponding parameter values in the
|
||||||
% other blocks of the model
|
% other blocks of the model
|
||||||
|
@ -18,6 +18,7 @@ function varargout = pooled_ols(ds, param_common, param_regex, overlapping_dates
|
||||||
% param_names [cellstr] list of parameters to estimate (if
|
% param_names [cellstr] list of parameters to estimate (if
|
||||||
% empty, estimate all) (may contain regex
|
% empty, estimate all) (may contain regex
|
||||||
% to match param_regex)
|
% to match param_regex)
|
||||||
|
% ds_range [dates] range of dates to use in estimation
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% return arguments common to pooled_fgls only if called from pooled_fgls
|
% return arguments common to pooled_fgls only if called from pooled_fgls
|
||||||
|
@ -46,7 +47,7 @@ function varargout = pooled_ols(ds, param_common, param_regex, overlapping_dates
|
||||||
global M_ oo_
|
global M_ oo_
|
||||||
|
|
||||||
%% Check input arguments
|
%% Check input arguments
|
||||||
if nargin < 1 || nargin > 7
|
if nargin < 1 || nargin > 8
|
||||||
error('Incorrect number of arguments')
|
error('Incorrect number of arguments')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,8 +55,24 @@ if isempty(ds) || ~isdseries(ds)
|
||||||
error('The first argument must be a dseries');
|
error('The first argument must be a dseries');
|
||||||
end
|
end
|
||||||
|
|
||||||
if nargin < 5
|
if nargin < 8
|
||||||
eqtags = {};
|
ds_range = ds.dates;
|
||||||
|
else
|
||||||
|
if isempty(ds_range)
|
||||||
|
ds_range = ds.dates;
|
||||||
|
else
|
||||||
|
if ds_range(1) < ds.firstdate || ds_range(end) > lastdate(ds)
|
||||||
|
error('There is a problem with the 8th argument: the date range does not correspond to that of the dseries')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if nargin < 7
|
||||||
|
param_names = {};
|
||||||
|
else
|
||||||
|
if ~isempty(param_names) && ~iscellstr(param_names)
|
||||||
|
error('The 7th argument, if provided, must be a cellstr')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
st = dbstack(1);
|
st = dbstack(1);
|
||||||
|
@ -77,9 +94,13 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if nargin < 5
|
||||||
|
eqtags = {};
|
||||||
|
end
|
||||||
|
|
||||||
if isempty(param_common) && isempty(param_regex)
|
if isempty(param_common) && isempty(param_regex)
|
||||||
disp('Performing OLS instead of Pooled OLS...')
|
disp('Performing OLS instead of Pooled OLS...')
|
||||||
dyn_ols(ds, {}, eqtags);
|
dyn_ols(ds, {}, eqtags, model_name, param_names, ds_range);
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,13 +113,7 @@ else
|
||||||
assert(islogical(overlapping_dates) && length(overlapping_dates) == 1, 'The fourth argument must be a bool');
|
assert(islogical(overlapping_dates) && length(overlapping_dates) == 1, 'The fourth argument must be a bool');
|
||||||
end
|
end
|
||||||
|
|
||||||
if nargin < 7
|
|
||||||
param_names = {};
|
|
||||||
else
|
|
||||||
if ~isempty(param_names) && ~iscellstr(param_names)
|
|
||||||
error('The 7th argument, if provided, must be a cellstr')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Get Equation(s)
|
%% Get Equation(s)
|
||||||
ast = get_ast(eqtags);
|
ast = get_ast(eqtags);
|
||||||
|
@ -115,7 +130,7 @@ for i = 1:length(param_names)
|
||||||
end
|
end
|
||||||
|
|
||||||
%% Find parameters and variable names in every equation & Setup estimation matrices
|
%% Find parameters and variable names in every equation & Setup estimation matrices
|
||||||
[Y, lhssub, X, ~, ~, residnames] = common_parsing(ds, ast, overlapping_dates, param_names);
|
[Y, lhssub, X, ~, ~, residnames] = common_parsing(ds(ds_range), ast, overlapping_dates, param_names);
|
||||||
clear ast
|
clear ast
|
||||||
nobs = zeros(length(Y), 1);
|
nobs = zeros(length(Y), 1);
|
||||||
nobs(1) = Y{1}.nobs;
|
nobs(1) = Y{1}.nobs;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function varargout = sur(ds, param_names, eqtags, model_name, noniterative)
|
function varargout = sur(ds, param_names, eqtags, model_name, noniterative, ds_range)
|
||||||
%function varargout = sur(ds, param_names, eqtags, model_name, noniterative)
|
%function varargout = sur(ds, param_names, eqtags, model_name, noniterative, ds_range)
|
||||||
% Seemingly Unrelated Regressions
|
% Seemingly Unrelated Regressions
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
|
@ -10,6 +10,7 @@ function varargout = sur(ds, param_names, eqtags, model_name, noniterative)
|
||||||
% model_name [string] name of model to be displayed with
|
% model_name [string] name of model to be displayed with
|
||||||
% report
|
% report
|
||||||
% noniterative [bool] if true use noniterative estimation method
|
% noniterative [bool] if true use noniterative estimation method
|
||||||
|
% ds_range [dates] range of dates to use in estimation
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% none
|
% none
|
||||||
|
@ -37,8 +38,24 @@ function varargout = sur(ds, param_names, eqtags, model_name, noniterative)
|
||||||
global M_ oo_ options_
|
global M_ oo_ options_
|
||||||
|
|
||||||
%% Check input argument
|
%% Check input argument
|
||||||
if nargin < 1 || nargin > 5
|
if nargin < 1 || nargin > 6
|
||||||
error('function takes between 1 and 5 arguments');
|
error('function takes between 1 and 6 arguments');
|
||||||
|
end
|
||||||
|
|
||||||
|
if isempty(ds) || ~isdseries(ds)
|
||||||
|
error('The first argument must be a dseries');
|
||||||
|
end
|
||||||
|
|
||||||
|
if nargin < 6
|
||||||
|
ds_range = ds.dates;
|
||||||
|
else
|
||||||
|
if isempty(ds_range)
|
||||||
|
ds_range = ds.dates;
|
||||||
|
else
|
||||||
|
if ds_range(1) < ds.firstdate || ds_range(end) > lastdate(ds)
|
||||||
|
error('There is a problem with the 6th argument: the date range does not correspond to that of the dseries')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nargin < 5
|
if nargin < 5
|
||||||
|
@ -81,7 +98,7 @@ ast = handle_constant_eqs(get_ast(eqtags));
|
||||||
neqs = length(ast);
|
neqs = length(ast);
|
||||||
|
|
||||||
%% Find parameters and variable names in equations and setup estimation matrices
|
%% Find parameters and variable names in equations and setup estimation matrices
|
||||||
[Y, lhssub, X, ~, ~, residnames] = common_parsing(ds, ast, true, param_names);
|
[Y, lhssub, X, ~, ~, residnames] = common_parsing(ds(ds_range), ast, true, param_names);
|
||||||
clear ast
|
clear ast
|
||||||
nobs = Y{1}.nobs;
|
nobs = Y{1}.nobs;
|
||||||
[Y, lhssub, X, constrained] = put_in_sur_form(Y, lhssub, X);
|
[Y, lhssub, X, constrained] = put_in_sur_form(Y, lhssub, X);
|
||||||
|
|
Loading…
Reference in New Issue