ujive1¶
- weak_instruments.ujive1.UJIVE1(Y: ndarray[tuple[int, ...], dtype[float64]], X: ndarray[tuple[int, ...], dtype[float64]], Z: ndarray[tuple[int, ...], dtype[float64]], G: ndarray[tuple[int, ...], dtype[float64]] | None = None, W: ndarray[tuple[int, ...], dtype[float64]] | None = None, talk: bool = False) UJIVE1Result ¶
Calculates the UJIVE1 estimator using a two-pass approach recommended by Angrist, Imbens, and Kreuger (1999) in Jackknife IV estimation.
- Parameters:
Y (NDArray[np.float64]) – A 1-D numpy array of the dependent variable (N x 1).
X (NDArray[np.float64]) – A 2-D numpy array of the endogenous regressors (N x L). Do not inlude the constant.
Z (NDArray[np.float64]) – A 2-D numpy array of the instruments (N x K), where K > L. Do not include the constant.
W (NDArray[np.float64]) – A 2-D numpy array of the exogenous controls (N x G). Do not include the constant. These are not necessary for the function.
talk (bool) – If True, provides detailed output for teaching / debugging purposes. Default is False.
- Returns:
- An object containing the following attributes:
beta (NDArray[np.float64]): The estimated coefficients for the model.
leverage (NDArray[np.float64]): The leverage values for each observation.
fitted_values (NDArray[np.float64]): The fitted values from the first pass of the UJIVE1 estimator.
r_squared (float): The R-squared value for the model.
adjusted_r_squared (float): The adjusted R-squared value for the model.
f_stat (float): The F-statistic for the model.
standard_errors (NDArray[np.float64]): The robust standard errors for the estimated coefficients.
- Return type:
- Raises:
ValueError – If the dimensions of Y, X, or Z are inconsistent or invalid.
RuntimeWarning – If the number of instruments (columns in Z) is not greater than the number of regressors (columns in X).
Notes
The JIVE1 estimator is a jackknife-based instrumental variable estimator designed to reduce bias in the presence of many instruments.
- The function performs a two-pass estimation:
The first pass calculates fitted values and leverage values using the instruments.
The second pass removes the ith observation to calculate unbiased estimates.
Additional statistics such as R-squared, adjusted R-squared, and F-statistics are calculated for model evaluation.
If the number of endogenous regressors is 1, first-stage statistics (R-squared and F-statistic) are also computed.
Example
>>> import numpy as np >>> from weak_instruments.ujive1 import UJIVE1 >>> Y = np.array([1, 2, 3]) >>> X = np.array([[1], [2], [3]]) >>> Z = np.array([[1, 0], [0, 1], [1, 1]]) >>> result = UJIVE1(Y, X, Z) >>> print(result.summary())
- class weak_instruments.ujive1.UJIVE1Result(beta: ndarray[tuple[int, ...], dtype[float64]], leverage: ndarray[tuple[int, ...], dtype[float64]], fitted_values: ndarray[tuple[int, ...], dtype[float64]], r_squared: ndarray[tuple[int, ...], dtype[float64]], adjusted_r_squared: ndarray[tuple[int, ...], dtype[float64]], f_stat: ndarray[tuple[int, ...], dtype[float64]], standard_errors: ndarray[tuple[int, ...], dtype[float64]], root_mse: ndarray[tuple[int, ...], dtype[float64]], pvals: ndarray[tuple[int, ...], dtype[float64]] | None = None, tstats: ndarray[tuple[int, ...], dtype[float64]] | None = None, cis: ndarray[tuple[int, ...], dtype[float64]] | None = None)¶
Bases:
object
Stores results for the UJIVE1 estimator.
- beta¶
Estimated coefficients.
- leverage¶
Leverage values for each observation.
- fitted_values¶
Fitted values from the first pass.
- r_squared¶
R-squared value.
- adjusted_r_squared¶
Adjusted R-squared value.
- f_stat¶
F-statistic.
- standard_errors¶
Robust standard errors.
- root_mse¶
Root mean squared error.
- pvals¶
p-values for coefficients.
- tstats¶
t-statistics for coefficients.
- cis¶
Confidence intervals for coefficients.
- summary()¶
Prints a summary of the UJIVE1 results in a tabular format similar to statsmodels OLS.