| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/ivreg.R |
| 3 |
\name{vcovCR.ivreg} |
| 4 |
\alias{vcovCR.ivreg} |
| 5 |
\title{Cluster-robust variance-covariance matrix for an ivreg object.} |
| 6 |
\usage{ |
| 7 |
\method{vcovCR}{ivreg}( |
| 8 |
obj, |
| 9 |
cluster, |
| 10 |
type, |
| 11 |
target = NULL, |
| 12 |
inverse_var = FALSE, |
| 13 |
form = "sandwich", |
| 14 |
... |
| 15 |
) |
| 16 |
} |
| 17 |
\arguments{ |
| 18 |
\item{obj}{Fitted model for which to calculate the variance-covariance matrix} |
| 19 |
|
| 20 |
\item{cluster}{Expression or vector indicating which observations belong to |
| 21 |
the same cluster. Required for \code{ivreg} objects.} |
| 22 |
|
| 23 |
\item{type}{Character string specifying which small-sample adjustment should |
| 24 |
be used, with available options \code{"CR0"}, \code{"CR1"}, \code{"CR1p"}, |
| 25 |
\code{"CR1S"}, \code{"CR2"}, or \code{"CR3"}. See "Details" section of |
| 26 |
\code{\link{vcovCR}} for further information.} |
| 27 |
|
| 28 |
\item{target}{Optional matrix or vector describing the working |
| 29 |
variance-covariance model used to calculate the \code{CR2} and \code{CR4} |
| 30 |
adjustment matrices. If a vector, the target matrix is assumed to be |
| 31 |
diagonal. If not specified, the target is taken to be an identity matrix.} |
| 32 |
|
| 33 |
\item{inverse_var}{Not used for \code{ivreg} objects.} |
| 34 |
|
| 35 |
\item{form}{Controls the form of the returned matrix. The default |
| 36 |
\code{"sandwich"} will return the sandwich variance-covariance matrix. |
| 37 |
Alternately, setting \code{form = "meat"} will return only the meat of the |
| 38 |
sandwich and setting \code{form = B}, where \code{B} is a matrix of |
| 39 |
appropriate dimension, will return the sandwich variance-covariance matrix |
| 40 |
calculated using \code{B} as the bread. \code{form = "estfun"} will return the |
| 41 |
(appropriately scaled) estimating function, the transposed crossproduct of |
| 42 |
which is equal to the sandwich variance-covariance matrix.} |
| 43 |
|
| 44 |
\item{...}{Additional arguments available for some classes of objects.} |
| 45 |
} |
| 46 |
\value{ |
| 47 |
An object of class \code{c("vcovCR","clubSandwich")}, which consists |
| 48 |
of a matrix of the estimated variance of and covariances between the |
| 49 |
regression coefficient estimates. |
| 50 |
} |
| 51 |
\description{ |
| 52 |
\code{vcovCR} returns a sandwich estimate of the variance-covariance matrix |
| 53 |
of a set of regression coefficient estimates from an ivreg object fitted |
| 54 |
from the \CRANpkg{AER} package or the \CRANpkg{ivreg} package. |
| 55 |
} |
| 56 |
\details{ |
| 57 |
For any "ivreg" objects fitted via the \code{\link[ivreg]{ivreg}} |
| 58 |
function from the \CRANpkg{ivreg} package, only traditional 2SLS |
| 59 |
regression method (method = "OLS") is supported. |
| 60 |
clubSandwich currently cannot support robust-regression methods such as |
| 61 |
M-estimation (method = "M") or MM-estimation (method = "MM"). |
| 62 |
} |
| 63 |
\examples{ |
| 64 |
|
| 65 |
if (requireNamespace("AER", quietly = TRUE)) withAutoprint({ |
| 66 |
|
| 67 |
library(AER) |
| 68 |
data("CigarettesSW") |
| 69 |
Cigs <- within(CigarettesSW, { |
| 70 |
rprice <- price/cpi |
| 71 |
rincome <- income/population/cpi |
| 72 |
tdiff <- (taxs - tax)/cpi |
| 73 |
}) |
| 74 |
|
| 75 |
iv_fit_AER <- AER::ivreg(log(packs) ~ log(rprice) + log(rincome) | |
| 76 |
log(rincome) + tdiff + I(tax/cpi), data = Cigs) |
| 77 |
vcovCR(iv_fit_AER, cluster = Cigs$state, type = "CR2") |
| 78 |
coef_test(iv_fit_AER, vcov = "CR2", cluster = Cigs$state) |
| 79 |
|
| 80 |
}) |
| 81 |
|
| 82 |
pkgs_available <- |
| 83 |
requireNamespace("AER", quietly = TRUE) & |
| 84 |
requireNamespace("ivreg", quietly = TRUE) |
| 85 |
|
| 86 |
if (pkgs_available) withAutoprint ({ |
| 87 |
|
| 88 |
data("CigarettesSW") |
| 89 |
Cigs <- within(CigarettesSW, { |
| 90 |
rprice <- price/cpi |
| 91 |
rincome <- income/population/cpi |
| 92 |
tdiff <- (taxs - tax)/cpi |
| 93 |
}) |
| 94 |
iv_fit_ivreg <- ivreg::ivreg(log(packs) ~ log(rprice) + log(rincome) | |
| 95 |
log(rincome) + tdiff + I(tax/cpi), data = Cigs) |
| 96 |
vcovCR(iv_fit_ivreg, cluster = Cigs$state, type = "CR2") |
| 97 |
coef_test(iv_fit_ivreg, vcov = "CR2", cluster = Cigs$state) |
| 98 |
}) |
| 99 |
|
| 100 |
} |
| 101 |
\seealso{ |
| 102 |
\code{\link{vcovCR}} |
| 103 |
} |