IV3SLS
(equations, *, sigma=None)[source]¶Threestage Least Squares (3SLS) Estimator
Parameters: 


Notes
Estimates a set of regressions which are seemingly unrelated in the sense that separate estimation would lead to consistent parameter estimates. Each equation is of the form
where k denotes the equation and i denoted the observation index. By stacking vertically arrays of dependent and placing the exogenous variables into a block diagonal array, the entire system can be compactly expressed as
where
and
The system instrumental variable (IV) estimator is
where \(\hat{X} = Z(Z'Z)^{1}Z'X\) and. When certain conditions are satisfied, a GLS estimator of the form
can improve accuracy of coefficient estimates where
where \(\Sigma\) is the covariance matrix of the residuals.
add_constraints
(r, q=None)[source]¶Parameters: 


Notes
Constraints are of the form
The property param_names can be used to determine the order of parameters.
constraints
¶Model constraints
Returns:  cons – Constraint object 

Return type:  LinearConstraint 
fit
(*, method=None, full_cov=True, iterate=False, iter_limit=100, tol=1e06, cov_type='robust', **cov_config)[source]¶Estimate model parameters
Parameters: 


Returns:  results – Estimation results 
Return type: 
formula
¶Set or get the formula used to construct the model
from_formula
(formula, data, *, sigma=None, weights=None)[source]¶Specify a 3SLS using the formula interface
Parameters: 


Returns:  model – Model instance 
Return type: 
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 Patsy 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 IV3SLS
>>> formula = {'eq1': 'y1 ~ 1 + x1_1 + [x1_2 ~ z1]',
... 'eq2': 'y2 ~ 1 + x2_1 + [x2_2 ~ z2]'}
>>> mod = IV3SLS.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 = IV3SLS.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 = IV3SLS.from_formula(formula, data)
has_constant
¶Vector indicating which equations contain constants
multivariate_ls
(dependent, exog=None, endog=None, instruments=None)[source]¶Interface for specification of multivariate IV models
Parameters: 


Returns:  model – Model instance 
Return type: 
Notes
At least one of exog or endog must be provided.
Utility function to simplify the construction of multivariate IV models which all use the same regressors and instruments. Constructs the dictionary of equations from the variables using the common exogenous, endogenous and instrumental variables.
param_names
¶Model parameter names
Returns:  names – Normalized, unique model parameter names 

Return type:  list[str] 
predict
(params, *, equations=None, data=None, eval_env=8)[source]¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not none, then equations must be none. Predictions from models constructed using formulas can be computed using either equations, which will treat these are arrays of values corresponding to the formulaprocess data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
When using exog and endog, the regressor array for a particular equation is assembled as [equations[eqn][‘exog’], equations[eqn][‘endog’]] where eqn is an equation label. These must correspond to the columns in the estimated model.
IVSystemGMM
(equations, *, sigma=None, weight_type='robust', **weight_config)[source]¶System Generalized Method of Moments (GMM) estimation of linear IV models
Parameters: 


Notes
Estimates a linear model using GMM. Each equation is of the form
where k denotes the equation and i denoted the observation index. By stacking vertically arrays of dependent and placing the exogenous variables into a block diagonal array, the entire system can be compactly expressed as
where
and
The system GMM estimator uses the moment condition
where j indexes the equation. The estimator for the coefficients is given by
where \(W\) is a positive definite weighting matrix.
add_constraints
(r, q=None)¶Parameters: 


Notes
Constraints are of the form
The property param_names can be used to determine the order of parameters.
constraints
¶Model constraints
Returns:  cons – Constraint object 

Return type:  LinearConstraint 
fit
(*, iter_limit=2, tol=1e06, initial_weight=None, cov_type='robust', **cov_config)[source]¶Estimate model parameters
Parameters: 


Returns:  results – Estimation results 
Return type: 
formula
¶Set or get the formula used to construct the model
from_formula
(formula, data, *, weights=None, weight_type='robust', **weight_config)[source]¶Specify a 3SLS using the formula interface
Parameters: 


Returns:  model – Model instance 
Return type: 
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 Patsy 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)
has_constant
¶Vector indicating which equations contain constants
multivariate_ls
(dependent, exog=None, endog=None, instruments=None)¶Interface for specification of multivariate IV models
Parameters: 


Returns:  model – Model instance 
Return type: 
Notes
At least one of exog or endog must be provided.
Utility function to simplify the construction of multivariate IV models which all use the same regressors and instruments. Constructs the dictionary of equations from the variables using the common exogenous, endogenous and instrumental variables.
param_names
¶Model parameter names
Returns:  names – Normalized, unique model parameter names 

Return type:  list[str] 
predict
(params, *, equations=None, data=None, eval_env=8)¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not none, then equations must be none. Predictions from models constructed using formulas can be computed using either equations, which will treat these are arrays of values corresponding to the formulaprocess data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
When using exog and endog, the regressor array for a particular equation is assembled as [equations[eqn][‘exog’], equations[eqn][‘endog’]] where eqn is an equation label. These must correspond to the columns in the estimated model.
reset_constraints
()¶Remove all model constraints