ivDiag: Omnibus Function for IV Estimation and Diagnostics

View source: R/ivDiag.R

ivDiagR Documentation

Omnibus Function for IV Estimation and Diagnostics

Description

Conducts various estimation and diagnostic procedure for instrumental variable designs in one shot.

Usage

ivDiag(data, Y, D, Z = NULL, controls = NULL, FE = NULL, cl = NULL, weights = NULL,
  bootstrap = TRUE, run.AR = TRUE,
  nboots = 1000, parallel = TRUE, cores = NULL, 
  seed = 94305, prec = 4, debug = FALSE,
  running = NULL, cutoff = 0, rd.poly = 1, bandwidth = NULL,
  kernel = "triangular")

Arguments

data

name of a dataframe.

Y

a string indicating the outcome variable.

D

a string indicating the treatment variable.

Z

a vector of strings indicating the instrumental variables. May be NULL when running is given; the instrument is then the indicator for crossing the cutoff. A factor or character instrument enters as dummy variables for all its levels but the first (base) level, named <instrument>_<level>, so a factor with K levels counts as K - 1 instruments. The tF procedure is then reported only for a factor with two levels.

controls

a vector of strings indicating the control variables.

FE

a vector of strings indicating the fixed effects variables.

cl

a string indicating the clustering variable.

weights

a string indicating the variable that stores weights.

bootstrap

whether to turn on bootstrap (TRUE by default).

run.AR

whether to run AR test (TRUE by default).

nboots

a numeric value indicating the number of bootstrap runs.

parallel

a logical flag controlling parallel computing.

cores

setting the number of cores.

prec

precision of CI in string (4 by default).

seed

seed for the bootstrap. Each bootstrap draw gets its own random-number stream derived from seed (via doRNG), so results are the same with or without parallel computing and for any number of cores.

debug

for debugging purposes.

running

a string indicating the running variable of a fuzzy regression discontinuity (RD) design. When it is given, the instrument is the indicator for crossing the cutoff (built when Z = NULL), and a polynomial in the distance to the cutoff, separate on each side, is added to controls, so that only the jump at the cutoff identifies the effect. A treatment predicted from the running variable (for example, from an assignment rule) is not a valid instrument on its own: it also varies smoothly with the running variable, and that variation overstates the first stage. If such a Z is supplied, it is used with the RD controls and a message is printed.

cutoff

the cutoff, or several cutoffs (each unit is then compared with its nearest cutoff, and cutoff fixed effects are added). 0 by default.

rd.poly

order of the polynomial in the running variable, 0 to 4 (1 by default).

bandwidth

keep units within this distance of the cutoff; NULL (the whole sample) by default. See rdrobust::rdbwselect for a data-driven choice.

kernel

"triangular" (default) or "uniform"; used only with a bandwidth. Kernel weights multiply weights.

Value

est_ols

results from an OLS regression.

est_2sls

results from a 2SLS regression.

AR

results from an Anderson-Rubin test

F_stat

various F statistics.

rho

Pearson correlation coefficient between the treatment and predicted treatment from the first stage regression (all covariates are partialled out).

tF

results from the tF procedure based on Lee et al. (2022)

est_rf

results from the reduced form regression.

est_fs

results from the first stage regression.

p_iv

the number of instruments.

N

the number of observations.

N_cl

the number of clusters.

df

the degree of freedom left from the 2SLS regression

nvalues

the unique values the outcome Y, the treatment D, and each instrument in Z in the 2SLS regression.

rd

with running only: the RD setup (running variable, cutoffs, polynomial order, bandwidth, kernel) and the number of units on each side of the cutoff.

Author(s)

Apoorva Lal; Yiqing Xu

References

Lal, Apoorva, Mackenzie Lockhart, Yiqing Xu, and Ziwen Zu. 2024. "How Much Should We Trust Instrumental Variable Estimates in Political Science? Practical Advice Based on 67 Replicated Studies." Political Analysis 32 (4): 521–540. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1017/pan.2024.2")}

Lee, David S, Justin McCrary, Marcelo J Moreira, and Jack Porter. 2022. "Valid t-Ratio Inference for IV." American Economic Review 112 (10): 3260–90.

See Also

plot_coef eff_F AR_test tF

Examples

data(ivDiag)
g <- ivDiag(data = mcclendon, Y = "intended", D = "openedesteem", 
    Z = "esteem", bootstrap = FALSE)
plot_coef(g)

ivDiag documentation built on Nov. 12, 2026, 5:06 p.m.