iode.Equations.estimate

Equations.estimate(from_period: str | Period = None, to_period: str | Period = None, list_eqs: str | List[str] = None, quiet: bool = False) bool[source]

Estimate an equation or a block of equations.

At the end of the estimation process, certain variables and scalars are automatically created if the process has converged. These variables and scalars can be used for computational purposes and, as they are part of the global workspace, can be saved for future use.

The tests resulting from the last estimation are saved as scalars. The same applies to residuals, left-hand and right-hand members of equations.

Saved tests (as scalars) have the following names (e<ith>_* for the <ith> equation of the block):

  • e<ith>_n : number of sample periods

  • e<ith>_k : number of estimated coefficients

  • e<ith>_stdev : std dev of residuals

  • e<ith>_meany : mean of Y

  • e<ith>_ssres : sum of squares of residuals

  • e<ith>_stderr : std error

  • e<ith>_stderrp : std error percent (in %)

  • e<ith>_fstat : F-Stat

  • e<ith>_r2 : R square

  • e<ith>_r2adj : adjusted R-squared

  • e<ith>_dw : Durbin-Watson

  • e<ith>_loglik : Log Likelihood

Calculated series are saved in special variables:

  • _YCALC<i> : right-hand side of the <ith> equation in the block

  • _YOBS<i> : left-hand side of the <ith> equation in the block

  • _YRES<i> : residuals of the <ith> equation of the block

Outside the estimation sample, the series values are \(NA\).

Parameters:
from_periodstr or Period, optional

The starting period of the execution range. Defaults to the starting period of the current Variables sample.

to_periodstr or Period, optional

The ending period of the execution range. Defaults to the ending period of the current Variables sample.

list_eqs: str or list(str), optional

List of equations to be estimated. If not provided, all equations of the present Equations database will be estimated. Default to None (all equations).

quietbool, optional

If True, suppresses the log messages during the estimation process Default to False.

Returns:
bool

True if the estimation process has converged, False otherwise.

Warning

If some equations to be estimated belongs to a same block, the block (Equation.block()), method (Equation.method()), and instruments (’Equation.instruments()) of each of them must have been updated before.

Examples

>>> from iode import SAMPLE_DATA_DIR, equations, scalars, variables
>>> equations.load(f"{SAMPLE_DATA_DIR}/fun.eqs")
Loading .../fun.eqs
274 objects loaded 
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> equations["ACAF"].lec
'(ACAF/VAF[-1]) :=acaf1+acaf2*GOSF[-1]+\nacaf4*(TIME=1995)'
>>> equations["DPUH"].lec
'dln (DPUH/DPUHO):=dpuh_1+dpuh_2*dln(IHU/PI5)+dln PC'
>>> # create scalars
>>> scalars["acaf1"] = 0., 1.
>>> scalars["acaf2"] = 0., 1.
>>> scalars["acaf4"] = 0., 1.
>>> scalars["dpuh_1"] = 0., 1.
>>> scalars["dpuh_2"] = 0., 1.
>>> # estimate an equation
>>> success = equations.estimate("1980Y1", "2000Y1", "ACAF")
Estimating : iteration 1 (||eps|| = 0.173205)

Estimating : iteration 2 (||eps|| = 9.24137e-09)

Solution reached after 2 iteration(s). Creating results file ...

>>> success
True
>>> # or equivalenty
>>> success = equations["ACAF"].estimate("1980Y1", "2000Y1")
Estimating : iteration 1 (||eps|| = 1.93451e-13)

Solution reached after 1 iteration(s). Creating results file ...

>>> scalars["acaf1"]
Scalar(0.0150646, 1, 0.00118455)
>>> scalars["acaf2"]
Scalar(-6.90855e-06, 1, 1.07873e-06)
>>> scalars["acaf4"]
Scalar(-0.00915675, 1, 0.00209541)
>>> scalars["dpuh_1"]
Scalar(0, 1, na)
>>> scalars["dpuh_2"]
Scalar(0, 1, na)
>>> equations["ACAF"]
Equation(endogenous = 'ACAF',
        lec = '(ACAF/VAF[-1]) :=acaf1+acaf2*GOSF[-1]+\nacaf4*(TIME=1995)',
        method = 'LSQ',
        from_period = '1980Y1',
        to_period = '2000Y1',
        block = 'ACAF',
        tests = {corr = 1,
                 dw = 1.87449,
                 fstat = 34.6629,
                 loglik = 102.07,
                 meany = 0.0075289,
                 r2 = 0.793875,
                 r2adj = 0.770973,
                 ssres = 7.37883e-05,
                 stderr = 0.00202468,
                 stderrp = 26.8922,
                 stdev = 0.00423072},
        date = '...')
>>> # observed values (left hand side of the equation)
>>> variables["_YOBS0", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

 name      1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YOBS0       0.01    0.02    0.01  ...    0.01    0.00    0.00

>>> # fitted values (right hand side of the equation)
>>> variables["_YCALC0", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

  name     1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YCALC0      0.01    0.01    0.01  ...    0.00    0.00    0.00

>>> # residuals values
>>> variables["_YRES0", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

 name      1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YRES0      -0.00    0.00   -0.00  ...    0.00   -0.00   -0.00
>>> # estimate a block
>>> # prepare equations (same block and method)
>>> block = "ACAF;DPUH"
>>> equations["ACAF"] = {"block": block, "method": "LSQ"}
>>> equations["DPUH"] = {"block": block, "method": "LSQ"}
>>> success = equations.estimate("1980Y1", "2000Y1", block)
Estimating : iteration 1 (||eps|| = 0.141421)

Estimating : iteration 2 (||eps|| = 1.56772e-12)

Solution reached after 2 iteration(s). Creating results file ...

Estimating : iteration 1 (||eps|| = 2.00302e-12)

Solution reached after 1 iteration(s). Creating results file ...

>>> success
True
>>> scalars["acaf1"]
Scalar(0.0150646, 1, 0.00117649)
>>> scalars["acaf2"]
Scalar(-6.90855e-06, 1, 1.07029e-06)
>>> scalars["acaf4"]
Scalar(-0.00915675, 1, 0.00207864)
>>> scalars["dpuh_1"]
Scalar(0.0120668, 1, 0.00388436)
>>> scalars["dpuh_2"]
Scalar(0.0547555, 1, 0.0312223)
>>> equations["ACAF"]
Equation(endogenous = 'ACAF',
        lec = '(ACAF/VAF[-1]) :=acaf1+acaf2*GOSF[-1]+\nacaf4*(TIME=1995)',
        method = 'LSQ',
        from_period = '1980Y1',
        to_period = '2000Y1',
        block = 'ACAF;DPUH',
        tests = {corr = 1,
                 dw = 1.87449,
                 fstat = 34.6629,
                 loglik = 102.07,
                 meany = 0.0075289,
                 r2 = 0.793875,
                 r2adj = 0.770973,
                 ssres = 7.37883e-05,
                 stderr = 0.00202468,
                 stderrp = 26.8922,
                 stdev = 0.00423072},
        date = '...')
>>> # observed values for ACAF
>>> variables["_YOBS0", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

 name      1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YOBS0       0.01    0.02    0.01  ...    0.01    0.00    0.00

>>> # fitted values for ACAF
>>> variables["_YCALC0", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

  name     1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YCALC0      0.01    0.01    0.01  ...    0.00    0.00    0.00

>>> # residuals values for ACAF
>>> variables["_YRES0", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

 name      1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YRES0      -0.00    0.00   -0.00  ...    0.00   -0.00   -0.00

>>> equations["DPUH"]
Equation(endogenous = 'DPUH',
        lec = 'dln (DPUH/DPUHO):=dpuh_1+dpuh_2*dln(IHU/PI5)+dln PC',
        method = 'LSQ',
        from_period = '1980Y1',
        to_period = '2000Y1',
        block = 'ACAF;DPUH',
        tests = {corr = 0.126322,
                 dw = 3.2465,
                 fstat = 8.71231,
                 loglik = 55.855,
                 meany = 0.0466199,
                 r2 = 0.314384,
                 r2adj = 0.278299,
                 ssres = 0.00601874,
                 stderr = 0.0177982,
                 stderrp = 38.1772,
                 stdev = 0.0209507},
        date = '...')
>>> # observed values for DPUH
>>> variables["_YOBS1", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

 name      1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YOBS1       0.06    0.09    0.07  ...    0.03    0.02    0.04

>>> # fitted values for DPUH
>>> variables["_YCALC1", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

  name     1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YCALC1      0.07    0.07    0.08  ...    0.02    0.02    0.03

>>> # residuals values for DPUH
>>> variables["_YRES1", "1980Y1:2000Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1980Y1:2000Y1
mode: LEVEL

 name      1980Y1  1981Y1  1982Y1  ...  1998Y1  1999Y1  2000Y1
_YRES1      -0.01    0.02   -0.02  ...    0.00    0.00    0.01