Skip to contents

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

Usage

idid_weights(reg, var_interest, partial_iv = TRUE, ...)

Arguments

reg

A regression object.

var_interest

A string. The name of the main variable 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.

...

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

Value

A numeric vector representing the identifying variation weights.

Details

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

They are computed by re-running the regression provided but replacing the independent variable by the variable of interest (and removing it 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            2            3            4            5            6 
#> 8.693583e-05 9.188898e-06 1.504876e-05 1.274063e-05 3.686616e-06 1.076007e-05