iode.Equations.from_frame

Equations.from_frame(df: DataFrame)[source]

Copy the pandas DataFrame df into the IODE Equations database. The equation names to copy are deduced from the index of the DataFrame.

Parameters:
df: DataFrame

pandas DataFrame containing the equations to copy into the Equations database. The passed DataFrame must at least contains:

  • an index containing the names of the equations

  • a column labeled ‘lec’ containing the LEC expressions of the equations.

Other possible columns are ‘method’, ‘sample’, ‘comment’, ‘instruments’ and ‘block’ (see Equation).

See also

Equations.from_series
Equations.to_frame

Notes

The index of the passed DataFrame is sorted in alphabetical order before copying to IODE Equations database.

Examples

>>> from iode import equations, variables
>>> import pandas as pd
>>> import numpy as np
>>> variables.clear()
>>> variables.sample = "1960Y1:2015Y1"
>>> equations.clear()
>>> len(equations)
0
>>> # create the pandas DataFrame
>>> columns=["lec", "method", "sample", "corr", "fstat", "r2", "date"]
>>> data = {"A": ["A := t", "LSQ", "1980Y1:2010Y1", 1.0, 0.79, 0.05, "12-06-1998"],
...         "B": ["B := grt A", "LSQ", "1980Y1:2010Y1", 1.0, 0.896, 0.15, "12-06-1998"],
...         "C": ["C := exp t", "ZELLNER", "1990Y1:", 1.0, 0.1258, 0.0225, ""],
...         "D": ["ln D := t", "MAX_LIKELIHOOD", "", 1.0, 0.358, 0.0698, "12-06-1998"],
...         "E": ["1/E := B", "LSQ", ":2010Y1", 1.0, 0.689, 2.23e-03, ""],
...         "F": ["d(F) := t + 1", "GLS", "", 1.0, 0.05, 4.568e-04, ""]}
>>> df = pd.DataFrame.from_dict(data, orient='index', columns=columns)
>>> # display the pandas series
>>> df
             lec          method         sample  ...   fstat        r2        date
A         A := t             LSQ  1980Y1:2010Y1  ...  0.7900  0.050000  12-06-1998
B     B := grt A             LSQ  1980Y1:2010Y1  ...  0.8960  0.150000  12-06-1998
C     C := exp t         ZELLNER        1990Y1:  ...  0.1258  0.022500
D      ln D := t  MAX_LIKELIHOOD                 ...  0.3580  0.069800  12-06-1998
E       1/E := B             LSQ        :2010Y1  ...  0.6890  0.002230
F  d(F) := t + 1             GLS                 ...  0.0500  0.000457

[6 rows x 7 columns]
>>> # load into the IODE Equations database
>>> equations.from_frame(df)
>>> len(equations)
6
>>> equations.names
['A', 'B', 'C', 'D', 'E', 'F']
>>> df.loc["A"]
lec              A := t
method              LSQ
sample    1980Y1:2010Y1
corr                1.0
fstat              0.79
r2                 0.05
date         12-06-1998
Name: A, dtype: object
>>> equations["A"]
Equation(endogenous = 'A',
         lec = 'A := t',
         method = 'LSQ',
         from_period = '1980Y1',
         to_period = '2010Y1',
         tests = {corr = 1,
                  dw = 0,
                  fstat = 0.79,
                  loglik = 0,
                  meany = 0,
                  r2 = 0.05,
                  r2adj = 0,
                  ssres = 0,
                  stderr = 0,
                  stderrp = 0,
                  stdev = 0},
         date = '12-06-1998')
>>> df.loc["F"]
lec       d(F) := t + 1
method              GLS
sample
corr                1.0
fstat              0.05
r2             0.000457
date
Name: F, dtype: object
>>> equations["F"]
Equation(endogenous = 'F',
         lec = 'd(F) := t + 1',
         method = 'GLS',
         tests = {corr = 1,
                  dw = 0,
                  fstat = 0.05,
                  loglik = 0,
                  meany = 0,
                  r2 = 0.0004568,
                  r2adj = 0,
                  ssres = 0,
                  stderr = 0,
                  stderrp = 0,
                  stdev = 0})