iode.Variables.high_to_low

Variables.high_to_low(type_of_series: HighToLowType | str, filepath: str | Path, var_list: str | List[str])[source]

Build series of lower periodicity by (summing the / taking the average of the / taking the last observation of) sub-periods.

The list of specified series (variables) from the input file are loaded into the current Variables database and the periodicity of these series (variables) is modified simultaneously. The new periodicity is the one currently defined in the current Variables database.

The loaded series are added to or replace those (for existing names) in the current Variables database.

This procedure exists for the following cases:

  • monthly to annual (annual observation = sum of 12 months / average of 12 months / December value)

  • quarterly to annual (annual observation = sum of 4 quarters / average of 4 quarters / last quarter value)

  • monthly to quarterly (quarterly observation = sum of 3 months / average of 3 months / value for the last month of the quarter)

Three types of series are available:

  • SIM: addition of sub-periods data

  • MEAN: average of sub-periods data

  • LAST: last observation

In the case of a non-existent value (\(NA\)) for one of the sub-periods, the result is \(NA\).

Parameters:
type_of_seriesHighToLowType or str
Three types of series are available:
  • SUM : addition of sub-period data

  • MEAN : average of sub-period data

  • LAST : last observation

filepathstr or Path

Filepath to the source data file.

var_liststr or list(str)

List of variables to include in the transformation.

Examples

>>> from iode import SAMPLE_DATA_DIR, variables, HighToLowType
>>> variables.clear()
>>> # define a yearly sample
>>> variables.sample = "2000Y1:2020Y1"
>>> # input filepath
>>> filepath = f"{SAMPLE_DATA_DIR}/fun_q.var"

Last Obs in year

>>> variables.high_to_low(HighToLowType.LAST, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2010Y1":"2014Y1"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2010Y1:2014Y1
mode: LEVEL

name        2010Y1  2011Y1  2012Y1  2013Y1  2014Y1
ACAF        -37.83  -44.54  -55.56  -68.89  -83.34

>>> variables["ACAG", "2010Y1":"2014Y1"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2010Y1:2014Y1
mode: LEVEL

name        2010Y1  2011Y1  2012Y1  2013Y1  2014Y1
ACAG          7.06    7.32    7.58    7.84    8.11

Mean of year

>>> variables.high_to_low(HighToLowType.MEAN, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2010Y1":"2014Y1"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2010Y1:2014Y1
mode: LEVEL

name        2010Y1  2011Y1  2012Y1  2013Y1  2014Y1
ACAF        -37.83  -44.54  -55.56  -68.89  -83.34

>>> variables["ACAG", "2010Y1":"2014Y1"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2010Y1:2014Y1
mode: LEVEL

name        2010Y1  2011Y1  2012Y1  2013Y1  2014Y1
ACAG          7.06    7.32    7.58    7.84    8.11

Sum

>>> variables.high_to_low(HighToLowType.SUM, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2010Y1":"2014Y1"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2010Y1:2014Y1
mode: LEVEL

name         2010Y1  2011Y1  2012Y1  2013Y1  2014Y1
ACAF        -151.31 -178.18 -222.24 -275.58 -333.36

>>> variables["ACAG", "2010Y1":"2014Y1"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2010Y1:2014Y1
mode: LEVEL

name        2010Y1  2011Y1  2012Y1  2013Y1  2014Y1
ACAG         28.25   29.28   30.32   31.37   32.42