put_in_sur_form: simplify function and make robust to potential future changes in dseries

time-shift
Houtan Bastani 2019-02-11 16:36:25 +01:00
parent a3867a0b34
commit 874ba9a641
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
1 changed files with 8 additions and 9 deletions

View File

@ -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