Skip to content
Snippets Groups Projects
Verified Commit 7e552bb6 authored by Nikola Bokan's avatar Nikola Bokan Committed by Stéphane Adjemian
Browse files

Add conversion routine for annual data.

The routine converts annual data into quarterly data.
Currently two options are implemented:
- equal-per-quarter setting values in each corresponding quarter to
corresponding annual value
- cubic-spline applicable ONLY to flow variables

(cherry picked from commit 53ec34790610f1d8a400b1376876cf1bda3f8395)
(cherry picked from commit cdf249e78121dea324998f0c0e3211221c78682f)
parent 02c3c672
No related branches found
No related tags found
No related merge requests found
Checking pipeline status
function ts = dseriesA2Q(ds, method)
% INPUTS
% - ds [dseries] annual frequency object with n elements.
% - method [char] 1×m array, method used for the time aggregation, possible values are:
% - 'equal-per-quarter',
% - 'cubic-spline' (for flow variables)
%
% OUTPUTS
% - ts [dseries] quaterly frequency object with m<n elements.
% Copyright © 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
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isequal(ds.freq,1)
error('Conversion only allowed for annual data!')
end
dq = dates(4, [ds.dates.year(1) 1]):dates(4, [ds.dates.year(end) 4]);
dQ = unique(dq); % dQ.ndat will be the maximum number of periods in ts
tdata = NaN(dQ.ndat, ds.vobs);
switch method
case 'equal-per-quarter'
counter = 1;
for i = 1:4:dQ.ndat
tdata(i:i+3,:) = repmat(ds.data(counter,:), [4,1]);
counter = counter+1;
end
case 'cubic-spline'
for i = 1:length(ds.name)
dAO = firstobservedperiod(ds{ds.name{i}}).year(1):lastobservedperiod(ds{ds.name{i}}).year(1);
ids = find(dq.year(:,1)==dAO(1),1);
ide = find(dq.year(:,1)==dAO(end),1,'last');
qPoints = dAO(1):0.25:dAO(end);
tdata(ids+3:ide,i) = spline(dAO, ds{ds.name{i}}.data, qPoints); % First three datapoints are set to NaN
end
otherwise
error('Unknow method.')
end
ts = dseries(tdata, dQ, ds.name, ds.tex);
end
\ 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