Skip to content
Snippets Groups Projects
Commit 5e60907f authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Merge branch 'NaN_code' into 'master'

x13: replace NaN by proper missingcode value of x13

Closes #57

See merge request !46
parents 8b2af42a c0786192
No related branches found
No related tags found
1 merge request!46x13: replace NaN by proper missingcode value of x13
Pipeline #8889 failed
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment