Non user-facing class to estimate an IV model using a 2SLS estimator.
Inherits from the Feols class. Users should not directly instantiate this class, but rather use the feols() function. This class constructs the second-stage and instrument within arrays through the shared DemeanCache supplied by the estimation runner.
Parameters
Name
Type
Description
Default
FixestFormula
Formula
Parsed fixest formula, including the first stage.
required
data
pd.DataFrame
Estimation data, already converted to pandas and reindexed.
required
options
EstimationOptions
Every estimation option the fit is built with, as built by the estimation function.
required
lookup_demeaned_data
dict[frozenset[int], DemeanedData]
Demeaning cache shared across the models of one cache block.
required
lookup_preconditioner
Optional[dict[frozenset[int], Preconditioner]]
Preconditioner cache shared across the models of one cache block.
None
sample_split
SampleSplit or None
The variable and value by which the estimation sample was split. None if the model was fit on the entire input data set (minus dropping of missings etc). For all model classes.
None
Attributes
Name
Type
Description
_Z
np.ndarray
Processed instruments after handling multicollinearity.
_weights_type_feiv
str
Type of the weights variable defined in Feiv class. Either “aweights” for analytic weights or “fweights” for frequency weights.
_coefnames_z
list[str]
Names of coefficients for Z after handling multicollinearity.
collinearity_instruments
CollinearityCheck
Names and column mask of the instruments dropped by the rank check, set in get_fit().
capabilities
Capabilities
Inference and post-estimation features this model class supports.
sandwich
SandwichComponents
Weighted scores of the first-stage projection X_hat, the 2SLS Hessian X_hat’ W X_hat, and its inverse, set in get_fit().
_beta_hat
np.ndarray
Estimated regression coefficients.
fitted_values
FittedValues
In-sample predictions on the link and the response scale, set in get_fit().
_u_hat
np.ndarray
Residuals of the regression model.
first_stage
FirstStage
First-stage regression fitted after second-stage inference: the coefficients pi_hat, the fitted values X_hat, the residuals v_hat, the fitted first-stage model, the excluded instruments, and the instrument-strength diagnostics.
_data
pd.DataFrame
The data frame used in the estimation. None if arguments lean = True or store_data = False.
Raises
Name
Type
Description
IVIdentificationError
If the exogenous variables and instruments fully explain an endogenous variable, or the instruments add no explanatory power for it.
Examples
Feiv is returned by feols() when the formula includes an instrument block, i.e. depvar ~ exog + [endog ~ instruments] | fe.