diff --git a/matlab/ols/sur.m b/matlab/ols/sur.m index b0b709651..5b63d122c 100644 --- a/matlab/ols/sur.m +++ b/matlab/ols/sur.m @@ -1,9 +1,11 @@ -function varargout = sur(ds) -% function varargout = sur(ds) +function varargout = sur(ds, eqtags) +% function varargout = sur(ds, eqtags) % Seemingly Unrelated Regressions % % INPUTS -% ds [dseries] data to use in estimation +% ds [dseries] data to use in estimation +% eqtags [cellstr] names of equation tags to estimate. If empty, +% estimate all equations % % OUTPUTS % none @@ -31,6 +33,7 @@ function varargout = sur(ds) global M_ oo_ options_ %% Check input argument +assert(nargin == 1 || nargin == 2, 'You must provide one or two arguments'); assert(~isempty(ds) && isdseries(ds), 'The first argument must be a dseries'); %% Read JSON @@ -41,13 +44,17 @@ end jsonmodel = loadjson(jsonfile); jsonmodel = jsonmodel.model; -[lhs, rhs, lineno] = getEquationsByTags(jsonmodel); +if nargin == 1 + [lhs, rhs, lineno] = getEquationsByTags(jsonmodel); +else + [lhs, rhs, lineno] = getEquationsByTags(jsonmodel, 'name', eqtags); +end %% Find parameters and variable names in equations and setup estimation matrices [X, Y, startdates, enddates, startidxs, residnames, pbeta, vars, pidxs, surconstrainedparams] = ... pooled_sur_common(ds, lhs, rhs, lineno); -if size(X, 2) ~= M_.param_nbr +if nargin == 1 && size(X, 2) ~= M_.param_nbr warning(['Not all parameters were used in model: ' ... sprintf('%s', strjoin(setdiff(M_.param_names, pbeta), ', '))]); end diff --git a/matlab/surgibbs.m b/matlab/surgibbs.m index 2f0183d00..13ed43501 100644 --- a/matlab/surgibbs.m +++ b/matlab/surgibbs.m @@ -1,5 +1,5 @@ -function surgibbs(ds, param_names, beta0, A, ndraws, discarddraws, thin) -%function surgibbs(ds, param_names, beta0, A, ndraws, discarddraws, thin) +function surgibbs(ds, param_names, beta0, A, ndraws, discarddraws, thin, eqtags) +%function surgibbs(ds, param_names, beta0, A, ndraws, discarddraws, thin, eqtags) % Implements Gibbs Samipling for SUR % % INPUTS @@ -11,6 +11,8 @@ function surgibbs(ds, param_names, beta0, A, ndraws, discarddraws, thin) % ndraws [int] number of draws % discarddraws [int] number of draws to discard % thin [int] if thin == N, save every Nth draw +% eqtags [cellstr] names of equation tags to estimate. If empty, +% estimate all equations % % OUTPUTS % none @@ -44,7 +46,7 @@ function surgibbs(ds, param_names, beta0, A, ndraws, discarddraws, thin) global M_ oo_ %% Check input -assert(nargin == 5 || nargin == 6 || nargin == 7, 'Incorrect number of arguments passed to surgibbs'); +assert(nargin >= 5 && nargin <= 8, 'Incorrect number of arguments passed to surgibbs'); assert(isdseries(ds), 'The 1st argument must be a dseries'); assert(iscellstr(param_names), 'The 2nd argument must be a cellstr'); assert(isvector(beta0) && length(beta0) == length(param_names), ... @@ -67,12 +69,24 @@ else end %% Estimation -[nobs, pidxs, X, Y, m] = sur(ds); +if nargin == 8 + [nobs, pidxs, X, Y, m] = sur(ds, eqtags); +else + [nobs, pidxs, X, Y, m] = sur(ds); +end pnamesall = M_.param_names(pidxs); nparams = length(param_names); pidxs = zeros(nparams, 1); for i = 1:nparams - pidxs(i) = find(strcmp(param_names{i}, pnamesall)); + idxs = find(strcmp(param_names{i}, pnamesall)); + if isempty(idxs) + if ~isempty(eqtags) + error(['Could not find ' param_names{i} ... + ' in the provided equations specified by ' strjoin(eqtags, ',')]); + end + error('Unspecified error. Please report'); + end + pidxs(i) = idxs; end X = X(:, pidxs); beta = beta0;