ujive2

weak_instruments.ujive2.UJIVE2(Y: ndarray[tuple[int, ...], dtype[float64]], X: ndarray[tuple[int, ...], dtype[float64]], Z: ndarray[tuple[int, ...], dtype[float64]], W: ndarray[tuple[int, ...], dtype[float64]] | None = None, talk: bool = False) UJIVE2Result

Calculates the UJIVE2 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:

UJIVE1Result

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 JIVE2 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:
    1. The first pass calculates fitted values and leverage values using the instruments.

    2. 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.ujive2 import UJIVE2
>>> 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.ujive2.UJIVE2Result(beta: ndarray[tuple[int, ...], dtype[float64]], leverage: ndarray[tuple[int, ...], dtype[float64]], fitted_values: ndarray[tuple[int, ...], dtype[float64]], r_squared: float, adjusted_r_squared: float, f_stat: float, standard_errors: ndarray[tuple[int, ...], dtype[float64]], root_mse: float, 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 UJIVE2 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 UJIVE2 results in a tabular format similar to statsmodels OLS.