pooled_ols: support endogenous without parameters on RHS
parent
3c62bd63cf
commit
8541579d48
|
@ -143,36 +143,8 @@ for i = 1:length(lhs)
|
||||||
X = [X Xtmp];
|
X = [X Xtmp];
|
||||||
end
|
end
|
||||||
|
|
||||||
lhssub = dseries();
|
lhssub = getRhsToSubFromLhs(ds, rhs{i}, regex, [splitstrings; pnames]);
|
||||||
rhs_ = strsplit(rhs{i}, [splitstrings; pnames]);
|
|
||||||
for j = 1:length(rhs_)
|
|
||||||
rhsj = rhs_{j};
|
|
||||||
while ~isempty(rhsj)
|
|
||||||
minusstr = '';
|
|
||||||
if strcmp(rhsj(1), '-') || strcmp(rhsj(1), '+')
|
|
||||||
if length(rhsj) == 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if strcmp(rhsj(1), '-')
|
|
||||||
minusstr = '-';
|
|
||||||
end
|
|
||||||
rhsj = rhsj(2:end);
|
|
||||||
end
|
|
||||||
str = getStrMoveRight(rhsj);
|
|
||||||
if ~isempty(str)
|
|
||||||
try
|
|
||||||
lhssub = [lhssub eval(regexprep([minusstr str], regex, 'ds.$&'))];
|
|
||||||
lhssub.rename_(lhssub{lhssub.vobs}.name{:}, [minusstr str]);
|
|
||||||
catch
|
|
||||||
if ~any(strcmp(M_exo_trim, str))
|
|
||||||
error(['dyn_ols: problem evaluating ' minusstr str]);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rhsj = rhsj(length(str)+1:end);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Y = eval(regexprep(lhs{i}, regex, 'ds.$&'));
|
Y = eval(regexprep(lhs{i}, regex, 'ds.$&'));
|
||||||
for j = 1:lhssub.vobs
|
for j = 1:lhssub.vobs
|
||||||
Y = Y - lhssub{j};
|
Y = Y - lhssub{j};
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
function lhssub = getRhsToSubFromLhs(ds, rhs, regex, splits)
|
||||||
|
%function lhssub = getRhsToSubFromLhs(ds, rhs, regex, splits)
|
||||||
|
% Helper function that identifies variables on RHS that need to be
|
||||||
|
% subtracted from LHS of OLS-style equation
|
||||||
|
%
|
||||||
|
% INPUTS
|
||||||
|
% ds [dseries] data
|
||||||
|
% rhs [string] RHS as a string
|
||||||
|
% regex [string] regex expressing valid list of variables
|
||||||
|
% splits [cell array] strings to split out of equation on RHS
|
||||||
|
%
|
||||||
|
% OUTPUTS
|
||||||
|
% lhssub [dseries] data to subtract from LHS
|
||||||
|
%
|
||||||
|
% SPECIAL REQUIREMENTS
|
||||||
|
% none
|
||||||
|
|
||||||
|
% Copyright (C) 2017 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/>.
|
||||||
|
|
||||||
|
global M_
|
||||||
|
|
||||||
|
assert(isdseries(ds), 'The first argument must be a dseries');
|
||||||
|
assert(ischar(rhs), 'The second argument must be a string');
|
||||||
|
assert(ischar(regex), 'The third argument must be a string');
|
||||||
|
assert(iscell(splits), 'The fourth argument must be a cell');
|
||||||
|
|
||||||
|
M_exo_trim = cellstr(M_.exo_names);
|
||||||
|
lhssub = dseries();
|
||||||
|
rhs_ = strsplit(rhs, splits);
|
||||||
|
for j = 1:length(rhs_)
|
||||||
|
rhsj = rhs_{j};
|
||||||
|
while ~isempty(rhsj)
|
||||||
|
minusstr = '';
|
||||||
|
if strcmp(rhsj(1), '-') || strcmp(rhsj(1), '+')
|
||||||
|
if length(rhsj) == 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if strcmp(rhsj(1), '-')
|
||||||
|
minusstr = '-';
|
||||||
|
end
|
||||||
|
rhsj = rhsj(2:end);
|
||||||
|
end
|
||||||
|
str = getStrMoveRight(rhsj);
|
||||||
|
if ~isempty(str)
|
||||||
|
try
|
||||||
|
lhssub = [lhssub eval(regexprep([minusstr str], regex, 'ds.$&'))];
|
||||||
|
lhssub.rename_(lhssub{lhssub.vobs}.name{:}, [minusstr str]);
|
||||||
|
catch
|
||||||
|
if ~any(strcmp(M_exo_trim, str))
|
||||||
|
error(['pooled_ols: problem evaluating ' minusstr str]);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rhsj = rhsj(length(str)+1:end);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -114,6 +114,7 @@ for i = 1:length(lhs)
|
||||||
pnames = intersect(rhs_, M_param_names_trim);
|
pnames = intersect(rhs_, M_param_names_trim);
|
||||||
pidxs = zeros(length(pnames), 1);
|
pidxs = zeros(length(pnames), 1);
|
||||||
vnames = cell(1, length(pnames));
|
vnames = cell(1, length(pnames));
|
||||||
|
splitstrings = cell(length(pnames), 1);
|
||||||
xjdata = dseries;
|
xjdata = dseries;
|
||||||
for j = 1:length(pnames)
|
for j = 1:length(pnames)
|
||||||
createdvar = false;
|
createdvar = false;
|
||||||
|
@ -137,8 +138,14 @@ for i = 1:length(lhs)
|
||||||
getStrMoveRight(rhs{i}(endidx+1:end))];
|
getStrMoveRight(rhs{i}(endidx+1:end))];
|
||||||
elseif rhs{i}(startidx) == '*'
|
elseif rhs{i}(startidx) == '*'
|
||||||
vnames{j} = getStrMoveLeft(rhs{i}(1:startidx-1));
|
vnames{j} = getStrMoveLeft(rhs{i}(1:startidx-1));
|
||||||
|
splitstrings{j} = [vnames{j} '*' pnames{j}];
|
||||||
elseif rhs{i}(endidx) == '*'
|
elseif rhs{i}(endidx) == '*'
|
||||||
vnames{j} = getStrMoveRight(rhs{i}(endidx+1:end));
|
vnames{j} = getStrMoveRight(rhs{i}(endidx+1:end));
|
||||||
|
splitstrings{j} = [pnames{j} '*' vnames{j}];
|
||||||
|
if rhs{i}(startidx) == '-'
|
||||||
|
vnames{j} = ['-' vnames{j}];
|
||||||
|
splitstrings{j} = ['-' splitstrings{j}];
|
||||||
|
end
|
||||||
elseif rhs{i}(startidx) == '+' ...
|
elseif rhs{i}(startidx) == '+' ...
|
||||||
|| rhs{i}(startidx) == '-' ...
|
|| rhs{i}(startidx) == '-' ...
|
||||||
|| rhs{i}(endidx) == '+' ...
|
|| rhs{i}(endidx) == '+' ...
|
||||||
|
@ -152,6 +159,7 @@ for i = 1:length(lhs)
|
||||||
else
|
else
|
||||||
vnames{j} = 'intercept';
|
vnames{j} = 'intercept';
|
||||||
end
|
end
|
||||||
|
splitstrings{j} = vnames{j};
|
||||||
else
|
else
|
||||||
error('pooled_ols: Shouldn''t arrive here');
|
error('pooled_ols: Shouldn''t arrive here');
|
||||||
end
|
end
|
||||||
|
@ -165,6 +173,8 @@ for i = 1:length(lhs)
|
||||||
xjdata = [xjdata xjdatatmp];
|
xjdata = [xjdata xjdatatmp];
|
||||||
end
|
end
|
||||||
|
|
||||||
|
lhssub = getRhsToSubFromLhs(ds, rhs{i}, regex, [splitstrings; pnames]);
|
||||||
|
|
||||||
residuals = intersect(rhs_, cellstr(M_.exo_names));
|
residuals = intersect(rhs_, cellstr(M_.exo_names));
|
||||||
justvnames = regexprep(vnames, '\(-\d\)|log|exp|log10|[\(\)]', '');
|
justvnames = regexprep(vnames, '\(-\d\)|log|exp|log10|[\(\)]', '');
|
||||||
justvnames = regexp(justvnames, '[-+]', 'split');
|
justvnames = regexp(justvnames, '[-+]', 'split');
|
||||||
|
@ -183,15 +193,29 @@ for i = 1:length(lhs)
|
||||||
vars{i} = [vnames{:}];
|
vars{i} = [vnames{:}];
|
||||||
|
|
||||||
ydata = eval(regexprep(lhs{i}, regex, 'ds.$&'));
|
ydata = eval(regexprep(lhs{i}, regex, 'ds.$&'));
|
||||||
|
for j = 1:lhssub.vobs
|
||||||
|
ydata = ydata - lhssub{j};
|
||||||
|
end
|
||||||
|
|
||||||
fp = max(ydata.firstobservedperiod, xjdata.firstobservedperiod);
|
if isempty(xjdata)
|
||||||
lp = min(ydata.lastobservedperiod, xjdata.lastobservedperiod);
|
% AR(1) case
|
||||||
|
fp = ydata.firstobservedperiod;
|
||||||
startidxs(i) = length(Y) + 1;
|
lp = ydata.lastobservedperiod;
|
||||||
startdates{i} = fp;
|
startidxs(i) = length(Y) + 1;
|
||||||
enddates{i} = lp;
|
startdates{i} = fp;
|
||||||
Y(startidxs(i):startidxs(i)+lp-fp, 1) = ydata(fp:lp).data;
|
enddates{i} = lp;
|
||||||
X(startidxs(i):startidxs(i)+lp-fp, pidxs) = xjdata(fp:lp).data;
|
Y(startidxs(i):startidxs(i)+lp-fp, 1) = ydata(fp:lp).data;
|
||||||
|
X(startidxs(i):startidxs(i)+lp-fp, :) = zeros(ydata(fp:lp).nobs, columns(X));
|
||||||
|
else
|
||||||
|
fp = max(ydata.firstobservedperiod, xjdata.firstobservedperiod);
|
||||||
|
lp = min(ydata.lastobservedperiod, xjdata.lastobservedperiod);
|
||||||
|
|
||||||
|
startidxs(i) = length(Y) + 1;
|
||||||
|
startdates{i} = fp;
|
||||||
|
enddates{i} = lp;
|
||||||
|
Y(startidxs(i):startidxs(i)+lp-fp, 1) = ydata(fp:lp).data;
|
||||||
|
X(startidxs(i):startidxs(i)+lp-fp, pidxs) = xjdata(fp:lp).data;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if overlapping_dates
|
if overlapping_dates
|
||||||
|
|
|
@ -19,6 +19,14 @@ for i=1:NSIMS
|
||||||
M_.Sigma_e = Sigma_e;
|
M_.Sigma_e = Sigma_e;
|
||||||
simdata = simul_backward_model(dseries(firstobs, dates('1995Q1'), M_endo_names_trim), 10000);
|
simdata = simul_backward_model(dseries(firstobs, dates('1995Q1'), M_endo_names_trim), 10000);
|
||||||
simdata = simdata(simdata.dates(5001:6000));
|
simdata = simdata(simdata.dates(5001:6000));
|
||||||
|
names=regexp(simdata.name, 'res\w*');
|
||||||
|
idxs = [];
|
||||||
|
for i=1:length(names)
|
||||||
|
if isempty(names{i})
|
||||||
|
idxs = [idxs i];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
simdata = simdata{idxs};
|
||||||
pooled_fgls(simdata, ...
|
pooled_fgls(simdata, ...
|
||||||
{'de','u2'}, ...
|
{'de','u2'}, ...
|
||||||
{'*_q_yed_ecm_*_q_yed_L1', ...
|
{'*_q_yed_ecm_*_q_yed_L1', ...
|
||||||
|
|
|
@ -19,6 +19,14 @@ for i=1:NSIMS
|
||||||
M_.Sigma_e = Sigma_e;
|
M_.Sigma_e = Sigma_e;
|
||||||
simdata = simul_backward_model(dseries(firstobs, dates('1995Q1'), M_endo_names_trim), 10000);
|
simdata = simul_backward_model(dseries(firstobs, dates('1995Q1'), M_endo_names_trim), 10000);
|
||||||
simdata = simdata(simdata.dates(5001:6000));
|
simdata = simdata(simdata.dates(5001:6000));
|
||||||
|
names=regexp(simdata.name, 'res\w*');
|
||||||
|
idxs = [];
|
||||||
|
for j=1:length(names)
|
||||||
|
if isempty(names{j})
|
||||||
|
idxs = [idxs j];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
simdata = simdata{idxs};
|
||||||
pooled_ols(simdata, ...
|
pooled_ols(simdata, ...
|
||||||
{'de','u2'}, ...
|
{'de','u2'}, ...
|
||||||
{'*_q_yed_ecm_*_q_yed_L1', ...
|
{'*_q_yed_ecm_*_q_yed_L1', ...
|
||||||
|
|
Loading…
Reference in New Issue