From 874ba9a64184e6fc277c43c1ca23cded31e313b3 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 11 Feb 2019 16:36:25 +0100 Subject: [PATCH] put_in_sur_form: simplify function and make robust to potential future changes in dseries --- matlab/ols/put_in_sur_form.m | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/matlab/ols/put_in_sur_form.m b/matlab/ols/put_in_sur_form.m index 7ed8fe35b..40cb0ed08 100644 --- a/matlab/ols/put_in_sur_form.m +++ b/matlab/ols/put_in_sur_form.m @@ -66,18 +66,17 @@ for i = 1:neqs to_remove = []; nr = sum(nobs(1:i-1)); nxcol = size(X{i}, 2); - Xtmp = dseries([zeros(nr, nxcol); X{i}.data; zeros(nrows-nr-nobs(i), nxcol)], fd, X{i}.name); - for j = 1:length(X{i}.name) - idx = find(strcmp(Xmat.name, X{i}.name{j})); + names = X{i}.name; + Xtmp = dseries([zeros(nr, nxcol); X{i}.data; zeros(nrows-nr-nobs(i), nxcol)], fd, names); + Xmatnames = Xmat.name; + for j = 1:length(names) + idx = find(strcmp(Xmatnames, names{j})); if ~isempty(idx) - Xmat.(Xmat.name{idx}) = Xmat{idx} + Xtmp{j}; - to_remove = [to_remove j]; - constrained{end+1} = Xmat.name{idx}; + Xmat.(Xmatnames{idx}) = Xmat.(Xmatnames{idx}) + Xtmp.(names{j}); + Xtmp = Xtmp.remove(names{j}); + constrained{end+1} = Xmatnames{idx}; end end - for j = length(to_remove):-1:1 - Xtmp = Xtmp.remove(Xtmp.name{to_remove(j)}); - end if ~isempty(Xtmp) Xmat = [Xmat Xtmp]; end