Commit cff9c1f2 authored by Dóra Kocsis's avatar Dóra Kocsis

general cleanup: copyright, license, Readme.md, closes #5, closes #6

parent 7d0fc2d7
This diff is collapsed.
[![pipeline status](https://git.dynare.org/DoraK/mdbnomics/badges/master/pipeline.svg)](https://git.dynare.org/DoraK/mdbnomics/commits/master)
This MATLAB/Octave toolbox comes with routines to access DBnomics time series from MATLAB.
The package is compatible with MATLAB 2019b and following versions, and (almost compatible with)
the latest Octave version.
## Installation
The toolbox can be installed by cloning the Git repository:
~$ git clone https://git.dynare.org/DoraK/mdbnomics.git
or downloading a zip archive:
~$ wget https://git.dynare.org/DoraK/mdbnomics/-/archive/master/mdbnomics-master.zip
~$ unsip mdbnomics-master.zip
-$ mv mdbnomics-master mdbnomics
## Usage
Add the `mdbnomics/src` folder to the MATLAB/Octave path, and run the following command (on MATLAB/Octave) prompt:
>> initialize_mdbnomics()
which, depending on your system, will add the necessary subfolders to
the MATLAB/Octave path.
You are then ready to go. A full documentation will come soon.
## Examples
### Fetch one time series by ID
First, let's assume that we know which series we want to download.
A series identifier (ID) is defined by three values, formatted like this: `provider_code/dataset_code/series_code`.
The `fetch_series` function is used to construct the cell array.
For example, to fetch the time series `EA19.1.0.0.0.ZUTN` from the
[\"Unemployment rate\" [ZUTN] dataset](https://db.nomics.world/AMECO/ZUTN)
belonging to the [AMECO provider](https://db.nomics.world/AMECO):
>> df_id = fetch_series('series_ids',"AMECO/ZUTN/EA19.1.0.0.0.ZUTN");
The returned data is stored in the `df_id` variable. Its type is a cell array. To display the first 3 rows of the array
(including the column headers), type:
>> df_id(1:4,:)
616 cell array
Columns 1 through 5
{'x_frequency'} {'provider_code'} {'dataset_code'} {'dataset_name' } {'series_code' }
{'annual' } {'AMECO' } {'ZUTN' } {'Unemployment ra'} {'EA19.1.0.0.0.ZUTN'}
{'annual' } {'AMECO' } {'ZUTN' } {'Unemployment ra'} {'EA19.1.0.0.0.ZUTN'}
{'annual' } {'AMECO' } {'ZUTN' } {'Unemployment ra'} {'EA19.1.0.0.0.ZUTN'}
Columns 6 through 11
{'series_name' } {'original_period'} {'period' } {'original_value'} {'value'} {'freq'}
{'Annually (Per'} {'1960' } {'1960-01-01'} {'NA' } {[ NaN]} {'a' }
{'Annually (Per'} {'1961' } {'1961-01-01'} {'NA' } {[ NaN]} {'a' }
{'Annually (Per'} {'1962' } {'1962-01-01'} {'NA' } {[ NaN]} {'a' }
Columns 12 through 16
{'unit' } {'geo' } {'Frequency'} {'Unit' } {'Country' }
{'percentage-of-a'} {'ea19'} {'Annually' } {'(Percentage of '} {'Euro area'}
{'percentage-of-a'} {'ea19'} {'Annually' } {'(Percentage of '} {'Euro area'}
{'percentage-of-a'} {'ea19'} {'Annually' } {'(Percentage of '} {'Euro area'}
>>
In such cell array, you will always find at least those columns:
* x_frequency: (harmonized frequency generated by DBnomics)
* provider_code
* dataset_code
* dataset_name
* series_code
* series_name
* original_period: the period as returned by DBnomics
* period: the first day of original_period
* original_value (str or float): the observation value as returned by DBnomics, where not available values are represented by "NA"
* value (float or NaN): the observation value as returned by DBnomics, where not available values are represented by NaN
Followed by dimensions columns, corresponding to the dimensions of the dataset:
* dimensions labels: freq, unit, geo
* dimensions values labels: Frequency, Unit, Country
### Fetch two time series by ID
Again, let's assume that we know which series we want to download.
We can reuse the fetch_series function, this time with two series codes.
For example, to fetch the time series `EA19.1.0.0.0.ZUTN` and `DNK.1.0.0.0.ZUTN` from the
[\"Unemployment rate\" [ZUTN] dataset](https://db.nomics.world/AMECO/ZUTN)
belonging to the [AMECO provider](https://db.nomics.world/AMECO):
>> df_ids = fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN"]);
### Fetch time series by code mask
The code mask notation is a very concise way to select one or many time series at once.
It is not compatible with all the providers. In particular, only the providers from the following list accept code mask:
* BIS
* ECB
* Eurostat
* FED
* IMF
* IMF-WEO
* INSEE
* OECD
* WTO
Given 3 dimensions "frequency", "country" and "indicator", the user can select:
* one time series by giving its code: "M.FR.PCPIEC_IX"
* many series by enumerating dimensions codes: "M.FR+DE.PCPIEC_IX" is equivalent to ["M.FR.PCPIEC_IX", "M.DE.PCPIEC_IX"]
* many series by skipping a dimension, repeating "." in the code mask: "M..PCPIEC_IX" is equivalent to ["M.country1.PCPIEC_IX", "M.country2.PCPIEC_IX", ..., "M.countryN.PCPIEC_IX"]
Examples:
>> df_code_mask1 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX");
>> df_code_mask2 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', ".FR.PCPIEC_WT");
>> df_code_mask3 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M..PCPIEC_IX+PCPIA_IX", 'max_nb_series', 400);
### Fetch time series by dimension
Searching by dimension is a less concise way to select time series than using the code mask, but it's universal:
some fetchers are not compatible with the code mask notation. The following example fetches many series from the
["Doing Business" [DB]](https://db.nomics.world/WB/DB) dataset of the [World Bank](https://db.nomics.world/WB) provider, selecting for time series about France, Italy and Spain (`country` dimension),
and the indicator "Procedures required to start a business - Women (number)" (`indicator` dimension):
>> df_dims = fetch_series('provider_code',"WB",'dataset_code',"DB", 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
### Fetch time series by API link
When the dimensions, provider, dataset or series codes are unknown, the user can:
* go to the page of a dataset on DBnomics website, for example [Doing Business](https://db.nomics.world/WB/DB)
* select some dimensions by using the input widgets of the left column
* click on "Copy API link" in the menu of the "Download" button,
* use the `fetch_series_by_api_link` function such as below
>> df_link = fetch_series_by_api_link("https://api.db.nomics.world/v22/series/WB/DB?observations=1&dimensions=%7B%22country%22%3A%5B%22FR%22%2C%22IT%22%2C%22ES%22%5D%2C%22indicator%22%3A%5B%22IC.REG.COST.PC.FE.ZS.DRFN%22%5D%7D");
### Fetch time series from the cart
On the [cart page](https://db.nomics.world/cart) of the DBnomics website, click on "Copy API link" and copy-paste it as an argument of the fetch_series_by_api_link function.
Please note that when you update your cart, you have to copy this link again, because the link itself contains the IDs of the series in the cart.
>> df_cart = fetch_series_by_api_link("https://api.db.nomics.world/v22/series?series_ids=AMECO%2FZUTN%2FEA19.1.0.0.0.ZUTN&observations=1");
### Fetch time series with different frequencies
>> df_multi_freq = fetch_series('series_ids', ["BEA/NIUnderlyingDetail-U001BC/S315-A",...
"BEA/NIUnderlyingDetail-U001BC/S315-Q",...
"BEA/NIUnderlyingDetail-U001BC/S315-M"]);
### Transform time series
The routines can interact with the [Time Series Editor](https://editor.nomics.world/) to transform time series by applying filters to them.
Available filters are listed on the [filters page](https://editor.nomics.world/filters).
The Time Series Editor is usable via a web interface ([example with AMECO/ZUTN/EA19.1.0.0.0.ZUTN](https://editor.nomics.world/series?source=dbnomics&series_id=AMECO/ZUTN/EA19.1.0.0.0.ZUTN))
but you can call it directly from MATLAB. The user is also able to chain many filters.
Here is an example of how to interpolate two annual time series with a monthly frequency, using a spline interpolation:
>> filters_ = '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]';
>> df_filter = fetch_series('series_ids', "AMECO/ZUTN/EA19.1.0.0.0.ZUTN",'dbnomics_filters', filters_);
The first row of the final cell array changes when filters are used:
* period_middle_day: the middle day of original_period (can be useful when you compare graphically interpolated series and original ones)
* filtered (bool): True if the series is filtered
* series_code: same as before for original series, but the suffix _filtered is added for filtered series
* series_name: same as before for original series, but the suffix (filtered) is added for filtered series
\ No newline at end of file
function df = fetch_series(varargin)
% function fetch_series(varargin)
% Download time series from DBnomics.
%
% If not `None`, `dimensions` parameter must be a `dict` of dimensions (`list` of `str`), like so:
% `{"freq": ["A", "M"], "country": ["FR"]}`.
%
% If not `None`, `series_code` must be a `str`. It can be a series code (one series), or a "mask" (many series):
% - remove a constraint on a dimension, for example `M..PCPIEC_WT`;
% - enumerate many values for a dimension, separated by a '+', for example `M.FR+DE.PCPIEC_WT`;
% - combine these possibilities many times in the same SDMX filter.
%
% If the rightmost dimension value code is removed, then the final '.' can be removed too: `A.FR.` = `A.FR`.
%
% If not `None`, `series_ids` parameter must be a non-empty `list` of series IDs.
% A series ID is a string formatted like `provider_code/dataset_code/series_code`.
%
% If `max_nb_series` is `None`, a default value of 50 series will be used.
%
% Return a cell array.
%
% Returns a cell array.
%
% Examples:
% Fetch one series:
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX");
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', ".FR.PCPIEC_WT");
%
% - fetch one series:
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX")
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', ".FR.PCPIEC_WT")
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M..PCPIEC_IX+PCPIA_IX")
%
% - fetch all the series of a dataset:
% Fetch all the series of a dataset:
% fetch_series('provider_code', "AMECO", 'dataset_code', "UVGD", 'max_nb_series', 500);
%
% - fetch many series from different datasets:
% fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN", "IMF/CPI/A.AT.PCPIT_IX"])
% Fetch many series from different datasets:
% fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN", "IMF/CPI/A.AT.PCPIT_IX"]);
%
% - fetch many series from the same dataset, searching by dimension:
% fetch_series('provider_code', "AMECO", 'dataset_code', "ZUTN", dimensions={"geo": ["dnk"]})
%
% Fetch many series from the same dataset, searching by dimension:
% fetch_series('provider_code',"AMECO", 'dataset_code', "ZUTN", 'dimensions', '{"geo":["dnk"]}');
%
% POSSIBLE PARAMETERS
% provider_code [string] the code of the dataset provider.
% dataset_code [string] the code of the dataset.
% series_code [string] the code mask of the series. If provided, the provider_code and the dataset_code must specified.
% dimensions [char] dataset dimension codes. If provided it must be a string formatted like: '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}'.
% series_ids [string] list of series IDs. It is string formatted like `provider_code/dataset_code/series_code`. If provided, the provider_code and the dataset_code shouldn't be specified.
% max_nb_series [integer] maximum number of series requested by the API. If not provided, a default value of 50 series will be used.
% api_base_url [string] the base URL used for API requests. If not provided, a default value of: 'https://api.db.nomics.world/v22/' will be used.
% dbnomics_filters [char] filters to apply on the requested series. If provided it must be a string formatted like: '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]'.
%
% OUTPUTS
% df
%
% SPECIAL REQUIREMENTS
% When you (don't) use dimensions, you must specifiy provider_code and dataset_code.
% When you use series_code, you must specifiy provider_code and dataset_code.
% When you use series_ids, you must not specifiy provider_code nor dataset_code.
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
default_api_base_url = 'https://api.db.nomics.world/v22/';
default_editor_base_url = 'https://editor.nomics.world/api/v1/';
......@@ -43,7 +60,7 @@ validStringInput = @(x) isstring(x) || ischar(x) || iscellstr(x);
p.addParameter('provider_code', '', validStringInput);
p.addParameter('dataset_code', '', validStringInput);
p.addParameter('series_code', '', validStringInput);
p.addParameter('dimensions', @ischar); %if no dimensions specified, provider_code & dataset_code MUST BE GIVEN
p.addParameter('dimensions', @ischar);
p.addParameter('series_ids', '',validStringInput);
p.addParameter('max_nb_series', NaN, @isnumeric);
p.addParameter('api_base_url', default_api_base_url, validStringInput);
......
function df = fetch_series_by_api_link(api_link, varargin)
% function fetch_series_by_api_link(api_link, varargin)
% Fetch series given an "API link" URL.
% "API link" URLs can be found on DBnomics web site (https://db.nomics.world/) on dataset or series pages using "Download" buttons.
%
% Returns a cell array.
%
% Example:
% fetch_series_by_api_link("https://api.db.nomics.world/v22/series?provider_code=AMECO&dataset_code=ZUTN")
% fetch_series_by_api_link("https://api.db.nomics.world/v22/series?series_ids=AMECO%2FZUTN%2FEA19.1.0.0.0.ZUTN&observations=1");
%
% REQUIRED PARAMETERS
% api_link [string] the URL used for the API request.
%
% OPTIONAL PARAMETERS
% dbnomics_filters [char] filters to apply on the requested series. If provided it must be a string formatted like: '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]'.
% max_nb_series [integer] maximum number of series requested by the API. If not provided, a default value of 50 series will be used.
% editor_api_base_url [string] the editor URL used for API requests. If not provided, a default value of: 'https://editor.nomics.world/api/v1/' will be used.
%
% OUTPUTS
% df
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
default_editor_base_url = 'https://editor.nomics.world/api/v1/';
......
function response_json = fetch_series_page(series_endpoint_url,offset)
% Adapt series_endpoint_url and make API request
function response_json = fetch_series_page(series_endpoint_url, offset)
% function fetch_series_page(series_endpoint_url,offset)
% Adapts series_endpoint_url and makes API request. Returns JSON output
% with series characteristics.
%
% INPUTS
% series_endpoint_url [string] API link of series
% offset [integer] total number of series
%
% OUTPUTS
% response_json
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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 contains(series_endpoint_url, '?')
series_page_url = sprintf('%s%soffset=%i', series_endpoint_url, '&', offset);
......
function filtered_series = filter_series(series_list, dbnomics_filters, editor_api_base_url)
%FILTER_SERIES Summary of this function goes here
% Detailed explanation goes here
% function filter_series(series_list, dbnomics_filters, editor_api_base_url)
% Adapts editor_api_base_url and returns the cell array of filtered series.
%
% INPUTS
% series_list [cell array] cell array of series previously requested
% dbnomics_filters [string] string array of filters to apply on series
% editor_api_base_url [string] editor API link
%
% OUTPUTS
% filtered_series
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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 strcmp(editor_api_base_url(end),'/') == 0
editor_api_base_url = strcat(editor_api_base_url, '/');
end
......
function series = flatten_dbnomics_series(series)
% Adapt DBnomics series attributes to ease cell array construction.
% Rename some struct fields, remove other ones
% (the `series` struct is nested but we want a flat struct to build a cell array).
% function flatten_dbnomics_series(series)
% Adapts DBnomics series attributes to ease cell array construction.
% Normalizes the period and the value attributes, flattens the dimensions
% and observation attributes.
%
% INPUTS
% series [struct] struct of series previously requested
%
% OUTPUTS
% series
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
series = normalize_period(series);
series = normalize_value(series);
......
function series = flatten_editor_series(series, dbnomics_series)
% Adapt Time Series Editor series attributes to ease DataFrame construction.
% function flatten_editor_series(series, dbnomics_series)
% Adapts Time Series Editor series attributes to ease cell array construction.
%
% INPUTS
% series [struct] struct of the filtered series returned by the POST request
% dbnomics_series [struct] struct of the original series returned by the API request
%
% OUTPUTS
% series
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
series = normalize_period(series);
series = normalize_value(series);
......
function filtered_series_list = iter_filtered_series(series_list, dbnomics_filters, apply_endpoint_url)
% function iter_filtered_series(series_list, dbnomics_filters, apply_endpoint_url)
% Adapts series to make POST request. Returns cell array of filtered series.
%
% INPUTS
% series_list [cell array] cell array of series previously requested
% dbnomics_filters [string] string array of filters to apply on series
% apply_endpoint_url [string] modified editor API link
%
% OUTPUTS
% filtered_series_list
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
editor_apply_endpoint_nb_series_per_post = 100;
opts = weboptions('ContentType','json', 'MediaType','application/json', 'RequestMethod','POST');
......
function [datasets_dimensions, series_dims_by_dataset_code, series_list] = iter_series_info(api_link, max_nb_series)
% Iterate through series.docs returned by API
% Returns structs of dataset(s) dimensions and series.
% function iter_series_info(api_link, max_nb_series)
% Makes API request. Iterates through series.docs returned by the API.
% Returns structs of the dataset(s)' dimensions and series.
% The answer can have a key 'dataset_dimensions' if only one dataset is returned by API, or 'datasets_dimensions' if
% more than one dataset is returned.
% - datasets_dimensions or dataset_dimensions don't change between calls
% - series is the current series
% Example:
% {
% 'datasets_dimensions': {
% "AMECO/ZUTN": {
% "code": "ZUTN",
% "converted_at": "2019-05-08T02:51:04Z",
% "dimensions_codes_order": ["freq", "unit", "geo" ...],
% ...
% },
% "CEPII/CHELEM-TRADE-GTAP": {
% "code": "CHELEM-TRADE-GTAP",
% "converted_at": "2019-01-29T15:53:30Z",
% "dimensions_codes_order": ["exporter", "importer", "secgroup", ...],
% ...
% },
% 'series':
% }
%
% INPUTS
% api_link [string] modified API link
% max_nb_series [integer] maximum number of series requested by the API
%
% OUTPUTS
% datasets_dimensions, series_dims_by_dataset_code, series_list
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
default_max_nb_series = 50;
total_nb_series = 0;
......
function series = normalize_period(series)
% Keep original period and convert str to datetime.
% Modifies `series`
% function normalize_period(series)
% Modifies series. Keeps original period and converts string to datetime.
% Returns modified series.
%
% INPUTS
% series [struct] original series struct returned by the API
%
% OUTPUTS
% series
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
period = series.period;
period_start_day = series.period_start_day;
series = rmfield(series, "period_start_day");
......
function series = normalize_value(series)
% Keep original value and convert "NA" to NaN (or user specified value).
% Modifies `series`
% function normalize_value(series)
% Modifies series. Keeps original value and converts "NA" to NaN.
% Returns modified series.
%
% INPUTS
% series [struct] series struct returned after period normalization
%
% OUTPUTS
% series
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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 iscell(series.value)
series.original_value = series.value;
value = series.value;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment