Skip to content
Snippets Groups Projects
Verified Commit 3aeb1ff7 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Fix pac.estimate.iterate_ols.

Was crashing if the auxiliary model contains a constant.

See https://forum.dynare.org/t/iterative-ols-for-pac-equation/21379.
parent da39af4a
Branches
No related tags found
No related merge requests found
...@@ -120,21 +120,32 @@ end ...@@ -120,21 +120,32 @@ end
% Build PAC expectation matrix expression. % Build PAC expectation matrix expression.
dataForPACExpectation = dseries(); dataForPACExpectation = dseries();
listofvariables = {}; listofvariables = {};
isconstant = false;
for i=1:length(M_.pac.(pacmodl).h_param_indices) for i=1:length(M_.pac.(pacmodl).h_param_indices)
match = regexp(rhs, sprintf('(?<var>((\\w*)|\\w*\\(-1\\)))\\*%s', M_.param_names{M_.pac.(pacmodl).h_param_indices(i)}), 'names'); match = regexp(rhs, sprintf('(?<var>((\\w*)|\\w*\\(-1\\)))\\*%s', M_.param_names{M_.pac.(pacmodl).h_param_indices(i)}), 'names');
if isempty(match) if isempty(match)
match = regexp(rhs, sprintf('%s\\*(?<var>((\\w*\\(-1\\))|(\\w*)))', M_.param_names{M_.pac.(pacmodl).h_param_indices(i)}), 'names'); match = regexp(rhs, sprintf('%s\\*(?<var>((\\w*\\(-1\\))|(\\w*)))', M_.param_names{M_.pac.(pacmodl).h_param_indices(i)}), 'names');
end end
if ~isempty(match)
if isempty(strfind(match.var, '(-1)')) if isempty(strfind(match.var, '(-1)'))
listofvariables{i} = match.var; listofvariables{end+1} = match.var;
dataForPACExpectation = [dataForPACExpectation, data{listofvariables{i}}]; dataForPACExpectation = [dataForPACExpectation, data{listofvariables{i}}];
else else
listofvariables{i} = match.var(1:end-4); listofvariables{end+1} = match.var(1:end-4);
dataForPACExpectation = [dataForPACExpectation, data{match.var(1:end-4)}.lag(1)]; dataForPACExpectation = [dataForPACExpectation, data{match.var(1:end-4)}.lag(1)];
end end
else
if strcmp(M_.param_names{M_.pac.(pacmodl).h_param_indices(i)}, sprintf('h_%s_constant', pacmodl))
isconstant = true;
end
end
end end
dataPAC = dataForPACExpectation{listofvariables{:}}(range).data; dataPAC = dataForPACExpectation{listofvariables{:}}(range).data;
if isconstant
dataPAC = [ones(rows(dataPAC),1), dataPAC];
end
% Build data for non optimizing behaviour % Build data for non optimizing behaviour
if is_non_optimizing_agents if is_non_optimizing_agents
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment