Debian Codegraph @

man/vcovCR.iv_robust.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/iv_robust.R
3 \name{vcovCR.iv_robust}
4 \alias{vcovCR.iv_robust}
5 \title{Cluster-robust variance-covariance matrix for an
6 \code{estimatr::iv_robust} object.}
7 \usage{
8 \method{vcovCR}{iv_robust}(
9 obj,
10 cluster,
11 type,
12 target = NULL,
13 inverse_var = FALSE,
14 form = "sandwich",
15 ...
16 )
17 }
18 \arguments{
19 \item{obj}{Fitted model for which to calculate the variance-covariance matrix}
20
21 \item{cluster}{Vector indicating which observations belong to
22 the same cluster. Required for \code{iv_robust} objects unless the model
23 was fitted with a \code{clusters} argument.}
24
25 \item{type}{Character string specifying which small-sample adjustment should
26 be used, with available options \code{"CR0"}, \code{"CR1"}, \code{"CR1p"},
27 \code{"CR1S"}, \code{"CR2"}, or \code{"CR3"}. See "Details" section of
28 \code{\link{vcovCR}} for further information.}
29
30 \item{target}{Optional matrix or vector describing the working
31 variance-covariance model used to calculate the \code{CR2} and \code{CR4}
32 adjustment matrices. If a vector, the target matrix is assumed to be
33 diagonal. If not specified, the target is taken to be an identity matrix.}
34
35 \item{inverse_var}{Not used for \code{iv_robust} objects.}
36
37 \item{form}{Controls the form of the returned matrix. The default
38 \code{"sandwich"} will return the sandwich variance-covariance matrix.
39 Alternately, setting \code{form = "meat"} will return only the meat of the
40 sandwich and setting \code{form = B}, where \code{B} is a matrix of
41 appropriate dimension, will return the sandwich variance-covariance matrix
42 calculated using \code{B} as the bread. \code{form = "estfun"} will return the
43 (appropriately scaled) estimating function, the transposed crossproduct of
44 which is equal to the sandwich variance-covariance matrix.}
45
46 \item{...}{Additional arguments available for some classes of objects.}
47 }
48 \value{
49 An object of class \code{c("vcovCR","clubSandwich")}, which consists
50 of a matrix of the estimated variance of and covariances between the
51 regression coefficient estimates.
52 }
53 \description{
54 \code{vcovCR} returns a sandwich estimate of the variance-covariance matrix
55 of a set of regression coefficient estimates from an
56 \code{\link[estimatr]{iv_robust}} object.
57 }
58 \examples{
59
60 if (requireNamespace("estimatr", quietly = TRUE)) withAutoprint({
61 library(estimatr)
62
63 set.seed(20261201)
64 N <- 200
65 cluster <- factor(rep(1:20, each = 10))
66 z1 <- rnorm(N)
67 z2 <- rnorm(N)
68 x_exog <- rnorm(N)
69 x_endog <- 0.5 * z1 + 0.3 * z2 + rnorm(N)
70 y <- 1 + 2 * x_endog + 0.5 * x_exog + rnorm(N)
71 dat <- data.frame(y, x_endog, x_exog, z1, z2, cluster)
72
73 # Basic 2SLS with clusters and CR2
74 iv_fit <- iv_robust(
75 y ~ x_endog + x_exog | x_exog + z1 + z2,
76 data = dat,
77 clusters = cluster, se_type = "CR2"
78 )
79 vcovCR(iv_fit)
80 conf_int(iv_fit, vcov = "CR2")
81
82 # 2SLS with fixed effects
83 iv_fe <- iv_robust(
84 y ~ x_endog + x_exog | x_exog + z1 + z2,
85 fixed_effects = ~ cluster,
86 data = dat,
87 clusters = cluster,
88 se_type = "CR2"
89 )
90 vcovCR(iv_fe)
91 conf_int(iv_fe, vcov = "CR2")
92 })
93
94 }
95 \seealso{
96 \code{\link{vcovCR}}
97 }