| civ {civ} | R Documentation | 
Categorical Instrumental Variable Estimator.
Description
Implementation of the categorical instrumental variable estimator.
Usage
civ(y, D, Z, X = NULL, K = 2)
Arguments
| y | The outcome variable, a numerical vector. | 
| D | A matrix of endogenous variables. | 
| Z | A matrix of instruments, where the first column corresponds to the categorical instrument. | 
| X | An optional matrix of control variables. | 
| K | The number of support points of the estimated instrument
 | 
Value
civ returns an object of S3 class  civ. An object of
class civ is a list containing the following components:
- coef
- A vector of second-stage coefficient estimates. 
- iv_fit
- Object of class - ivregfrom the IV regression of- yon- Dand- Xusing the the estimated- \hat{F}_Kas an instrument for- D. See also- AER::ivreg()for details.
- kcmeans_fit
- Object of class - kcmeansfrom the K-Conditional-Means regression of- Don- Zand- X. See also- kcmeans::kcmeans()for details.
- K
- Pass-through of selected user-provided arguments. See above. 
References
Fox J, Kleiber C, Zeileis A (2023). "ivreg: Instrumental-Variables Regression by '2SLS', '2SM', or '2SMM', with Diagnostics". R package.
Wiemann T (2023). "Optimal Categorical Instruments."
Examples
# Simulate data from a simple IV model with 800 observations
nobs = 800 # sample size
Z <- sample(1:20, nobs, replace = TRUE) # observed instrument
Z0 <- Z %% 2 # underlying latent instrument
U_V <- matrix(rnorm(2 * nobs, 0, 1), nobs, 2) %*%
  chol(matrix(c(1, 0.6, 0.6, 1), 2, 2)) # first and second stage errors
D <- Z0 + U_V[, 2] # endogenous variable
y <- D + U_V[, 1] # outcome variable
# Estimate categorical instrument variable estimator with K = 2
civ_fit <- civ(y, D, Z, K = 3)
summary(civ_fit)