Skip to contents

Compute regression weights describing the amount of variation used for identification.

Usage

idid_weights(reg, var_interest, partial_iv = TRUE, tol = 1e-07, ...)

Arguments

reg

A regression object.

var_interest

A vector string. The name of the variables of interest.

partial_iv

A boolean. If TRUE, partials out the part of the endogenous variables that are not explained by the instruments. If the regression is not an IV (or not generated by AER::ivreg or fixest::feols with an instrumented part), the value of partial_iv has no impact on the outcome of the function.

tol

A numeric. Passed to the qr function. The tolerance for detecting linear dependencies in the columns of x_partialled.

...

Additional elements to pass to the regression function when partialling out controls.

Value

A numeric vector of the identifying variation weights for each observation.

Details

The weights correspond to the normalized leverage of each observation for the variables of interest after partialling out all controls.

The partailled out version of the design matrix (ie, of the set of variables of interest) is computed by re-running the regression provided in reg but sequentially replacing the independent variable by each of the variables of interest (and removing them from the set of regressors).

If the nature of the independent variable and of the variable of interest are different, one may want to change the estimation. For instance, if the independent variable is discrete and estimated via glm with the argument family = "binomial" and the dependent variable is continuous, one may want to provide the argument family = "gaussian" to idid_weights.

Examples

reg_ex_lm <- ggplot2::txhousing |>
  lm(formula = log(sales) ~ median + listings + city + as.factor(date))

idid_weights(reg_ex_lm, "median") |>
 head()
#> [1] 8.693583e-05 9.188898e-06 1.504876e-05 1.274063e-05 3.686616e-06
#> [6] 1.076007e-05