iode.Variables.low_to_high

Variables.low_to_high(type_of_series: LowToHighType | str, method: LowToHighMethod | str, filepath: str | Path, var_list: str | List[str])[source]

Build series with higher periodicity for stock data (Unemployment, Debt, …) or flow data (GNP, Deficit, …).

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:

  • annual to monthly

  • annual to quarterly

  • quarterly to monthly

Two types of series are available, one for stocks (STOCK), the other for flows (FLOW).

Three interpolation methods are available:

  • linear (LINEAR): A[1980Q{1,2,3,4}] = A[1979Y1] + i * (A[1980Y1] - A[1979Y1])/4 i = 1,2,3,4

  • cubic splines (CUBIC_SPLINES): cubic interpolation

  • step (STEP) : A[1980Q{1,2,3,4}] = A[1980Y1]

Parameters:
type_of_seriesLowToHighType or str
Two types of series are considered: ‘stock’ and ‘flow’:
  • STOCK: stock data (Unemployment, Debt, …)

  • FLOW: flow data (GNP, Deficit, …)

methodLowToHighMethod or str
Method to use for transformation. Three methods can be used:
  • LINEAR (‘L’): Linear interpolation

  • CUBIC_SPLINES (‘C’): Cubic Spliness

  • STEP (‘S’): Step

filepathstr or Path

Filepath to the source data file.

var_liststr or list(str)

List of variables to include in the transformation.

Returns:
None

Examples

>>> from iode import SAMPLE_DATA_DIR, variables, LowToHighType, LowToHighMethod
>>> variables.clear()
>>> # define a yearly sample
>>> variables.sample = "2010Q1:2020Q4"
>>> # input filepath
>>> filepath = f"{SAMPLE_DATA_DIR}/fun.var"

Linear interpolation / stock

>>> # "stock" -> the result is a linear interpolation of the 2 surrounding source values.
>>> variables.low_to_high(LowToHighType.STOCK, LowToHighMethod.LINEAR, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2014Q1":"2014Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2014Q1:2014Q4
mode: LEVEL

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAF        -72.51  -76.12  -79.73  -83.34

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

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAG         31.63   31.90   32.16   32.42

Linear interpolation / flow

>>> # "flow" -> the result is the source value divided by the nb of sub-periods. 
>>> variables.low_to_high(LowToHighType.FLOW, LowToHighMethod.LINEAR, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2014Q1":"2014Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2014Q1:2014Q4
mode: LEVEL

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAF        -20.84  -20.84  -20.84  -20.84

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

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAG          8.11    8.11    8.11    8.11

Cubic splines / stock

>>> variables.low_to_high(LowToHighType.STOCK, LowToHighMethod.CUBIC_SPLINES, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2012Q1":"2012Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2012Q1:2012Q4
mode: LEVEL

name        2012Q1  2012Q2  2012Q3  2012Q4
ACAF        -47.30  -50.05  -52.81  -55.56

>>> variables["ACAG", "2012Q1":"2012Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2012Q1:2012Q4
mode: LEVEL

name        2012Q1  2012Q2  2012Q3  2012Q4
ACAG         29.54   29.80   30.06   30.32

Cubic splines / flow

>>> variables.low_to_high(LowToHighType.FLOW, LowToHighMethod.CUBIC_SPLINES, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2012Q1":"2012Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2012Q1:2012Q4
mode: LEVEL

name        2012Q1  2012Q2  2012Q3  2012Q4
ACAF        -12.75  -13.44  -14.27  -15.10

>>> variables["ACAG", "2012Q1":"2012Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2012Q1:2012Q4
mode: LEVEL

name        2012Q1  2012Q2  2012Q3  2012Q4
ACAG          7.48    7.55    7.61    7.68

Step / stock

>>> # "stock" -> the result has the same value as the source
>>> variables.low_to_high(LowToHighType.STOCK, LowToHighMethod.STEP, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2014Q1":"2014Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2014Q1:2014Q4
mode: LEVEL

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAF        -83.34  -83.34  -83.34  -83.34

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

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAG         32.42   32.42   32.42   32.42

Step / flow

>>> # "flow" -> the result is the source value plus a portion of 
>>> # the difference between the 2 surrounding values in the source
>>> variables.low_to_high(LowToHighType.FLOW, LowToHighMethod.STEP, filepath, ["ACAF", "ACAG"])
>>> variables["ACAF", "2014Q1":"2014Q4"]
Workspace: Variables
nb variables: 1
filename: ws
sample: 2014Q1:2014Q4
mode: LEVEL

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAF        -20.84  -20.84  -20.84  -20.84

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

name        2014Q1  2014Q2  2014Q3  2014Q4
ACAG          8.11    8.11    8.11    8.11