diff --git a/src/@x13/run.m b/src/@x13/run.m index 1d0d24af8b78e55f009dca25fa00a927ab5f5db5..ed3075741575f0dc18f05a14ad93a1e0cdb314fb 100644 --- a/src/@x13/run.m +++ b/src/@x13/run.m @@ -51,7 +51,7 @@ if ~all(cellfun(@isempty, struct2cell(o.regression))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -66,7 +66,7 @@ if ~all(cellfun(@isempty, struct2cell(o.x11))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -106,7 +106,7 @@ if ~all(cellfun(@isempty, struct2cell(o.transform))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -129,7 +129,7 @@ if ~all(cellfun(@isempty, struct2cell(o.outlier))) header = strjoin(tmp.textdata(1)); header = strsplit(header, {'\t'}); header = header(1,2:end); - o.results.(savedoutput{i}) = dseries(data(:,2:end), o.y.init, regexprep(header,'\(|\)','')); + o.results.(savedoutput{i}) = dseries(data(:,2:end), o.y.firstobservedperiod, regexprep(header,'\(|\)','')); elseif lower(savedoutput{i}) == 'oit' header = strjoin(tmp.textdata(1,1)); header = strsplit(header, {'\t'}); @@ -230,7 +230,7 @@ if ~all(cellfun(@isempty, struct2cell(o.force))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -265,7 +265,7 @@ if ~all(cellfun(@isempty, struct2cell(o.seats))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -284,7 +284,7 @@ if ~all(cellfun(@isempty, struct2cell(o.x11regression))) else tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -335,12 +335,12 @@ if ~all(cellfun(@isempty, struct2cell(o.estimate))) header = strsplit(header, {'\t'}); header = regexprep(header(1,2:end),'( ||\-)',''); for j = 1:numel(header) - o.results.(savedoutput{i}).(header{j}) = dseries(data(:,j+1), o.y.init, header(j)); + o.results.(savedoutput{i}).(header{j}) = dseries(data(:,j+1), o.y.firstobservedperiod, header(j)); end elseif lower(savedoutput{i}) == 'rrs' - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); elseif lower(savedoutput{i}) == 'rsd' - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); elseif lower(savedoutput{i}) == 'rts' header = strjoin(tmp.textdata(1,1)); header = strsplit(header, {'\t'}); @@ -386,3 +386,27 @@ end % Save main generated output file. o.results.out = fileread(sprintf('%s.out', basename)); + +return % --*-- Unit tests --*-- + +%@test:1 +try + data_mat=[NaN; randn(20,1)]; + ts = dseries(data_mat,'1999Q1'); + o = x13(ts); + o.transform('function','auto'); + o.automdl('savelog','amd'); + o.x11('save','(d11)'); + o.run(); + deseasonalized_data = o.results.d11; + if deseasonalized_data.init~=dates('1999Q2') + t(1) = false; + else + t(1) = true; + end +catch + t(1) = false; +end +T = all(t); + +%@eof:1 \ No newline at end of file diff --git a/src/utilities/print/data2txt.m b/src/utilities/print/data2txt.m index e01346e7fb537bc3f20951b528d9ed87b8803564..55056b343671575c855ae0863409832c29a4a29d 100644 --- a/src/utilities/print/data2txt.m +++ b/src/utilities/print/data2txt.m @@ -2,7 +2,7 @@ function str= data2txt(y) % Prints a one dimensional array. -% Copyright © 2017 Dynare Team +% Copyright © 2017-2022 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -18,6 +18,49 @@ function str= data2txt(y) % along with Dynare. If not, see <https://www.gnu.org/licenses/>. str = mat2str(y); +str = strrep(str, 'NaN', '-99999'); str = strrep(str, '[', '(\n'); str = strrep(str, ';', '\n'); -str = strrep(str, ']', '\n)'); \ No newline at end of file +str = strrep(str, ']', '\n)'); + +return % --*-- Unit tests --*-- + +%@test:1 +try + data_mat=[NaN + 1 + 3 + 3 + 4 + 1 + 2 + 3 + 4 + 1.5 + 2.3 + 3.1 + NaN + 1.2 + NaN + 3 + 5]; + + + ts = dseries(data_mat,'1999Q1'); + o = x13(ts); + o.transform('function','log'); + o.automdl('savelog','amd'); + o.x11('save','(d11)'); + o.run(); + deseasonalized_data = o.results.d11; + if deseasonalized_data.nobs~=16 || deseasonalized_data.init~=dates('1999Q2') + t(1) = false; + else + t(1) = true; + end +catch + t(1) = false; +end +T = all(t); + +%@eof:1 \ No newline at end of file