linearmodels.system.model.IVSystemGMM.from_formula

classmethod IVSystemGMM.from_formula(formula, data, *, weights=None, weight_type='robust', **weight_config)[source]

Specify a 3SLS using the formula interface

Parameters
formula{str, dict-like}

Either a string or a dictionary of strings where each value in the dictionary represents a single equation. See Notes for a description of the accepted syntax

dataDataFrame

Frame containing named variables

weightsdict-like

Dictionary like object (e.g. a DataFrame) containing variable weights. Each entry must have the same number of observations as data. If an equation label is not a key weights, the weights will be set to unity

weight_typestr

Name of moment condition weight function to use in the GMM estimation. Valid options are:

  • “unadjusted”, “homoskedastic” - Assume moments are homoskedastic

  • “robust”, “heteroskedastic” - Allow for heteroskedasticity

**weight_config

Additional keyword arguments to pass to the moment condition weight function

Returns
modelIVSystemGMM

Model instance

Notes

Models can be specified in one of two ways. The first uses curly braces to encapsulate equations. The second uses a dictionary where each key is an equation name.

Examples

The simplest format uses standard formulas for each equation in a dictionary. Best practice is to use an Ordered Dictionary

>>> import pandas as pd
>>> import numpy as np
>>> cols = ["y1", "x1_1", "x1_2", "z1", "y2", "x2_1", "x2_2", "z2"]
>>> data = pd.DataFrame(np.random.randn(500, 8), columns=cols)
>>> from linearmodels.system import IVSystemGMM
>>> formula = {"eq1": "y1 ~ 1 + x1_1 + [x1_2 ~ z1]",
...            "eq2": "y2 ~ 1 + x2_1 + [x2_2 ~ z2]"}
>>> mod = IVSystemGMM.from_formula(formula, data)

The second format uses curly braces {} to surround distinct equations

>>> formula = "{y1 ~ 1 + x1_1 + [x1_2 ~ z1]} {y2 ~ 1 + x2_1 + [x2_2 ~ z2]}"
>>> mod = IVSystemGMM.from_formula(formula, data)

It is also possible to include equation labels when using curly braces

>>> formula = "{eq1: y1 ~ 1 + x1_1 + [x1_2 ~ z1]} {eq2: y2 ~ 1 + x2_1 + [x2_2 ~ z2]}"
>>> mod = IVSystemGMM.from_formula(formula, data)
Return type

IVSystemGMM