ivreg {ivreg} | R Documentation |
Instrumental-Variable Regression by 2SLS, 2SM, or 2SMM Estimation
Description
Fit instrumental-variable regression by two-stage least squares (2SLS). This is equivalent to direct instrumental-variables estimation when the number of instruments is equal to the number of regressors. Alternative robust-regression estimators are also provided, based on M-estimation (2SM) and MM-estimation (2SMM).
Usage
ivreg(
formula,
instruments,
data,
subset,
na.action,
weights,
offset,
contrasts = NULL,
model = TRUE,
y = TRUE,
x = FALSE,
method = c("OLS", "M", "MM"),
...
)
Arguments
formula , instruments |
formula specification(s) of the regression
relationship and the instruments. Either |
data |
an optional data frame containing the variables in the model.
By default the variables are taken from the environment of the
|
subset |
an optional vector specifying a subset of observations to be used in fitting the model. |
na.action |
a function that indicates what should happen when the data
contain |
weights |
an optional vector of weights to be used in the fitting process. |
offset |
an optional offset that can be used to specify an a priori known component to be included during fitting. |
contrasts |
an optional list. See the |
model , x , y |
logicals. If |
method |
the method used to fit the stage 1 and 2 regression:
|
... |
further arguments passed to |
Details
ivreg
is the high-level interface to the work-horse function
ivreg.fit
. A set of standard methods (including print
,
summary
, vcov
, anova
, predict
, residuals
,
terms
, model.matrix
, bread
, estfun
) is available
and described in ivregMethods
. For methods related to regression
diagnostics, see ivregDiagnostics
.
Regressors and instruments for ivreg
are most easily specified in a
formula with two parts on the right-hand side, e.g., y ~ x1 + x2 | z1
+ z2 + z3
, where x1
and x2
are the explanatory variables and z1
,
z2
, and z3
are the instrumental variables. Note that exogenous regressors
have to be included as instruments for themselves.
For example, if there is
one exogenous regressor ex
and one endogenous regressor en
with instrument in
, the appropriate formula would be y ~ en +
ex | in + ex
. Alternatively, a formula with three parts on the right-hand
side can also be used: y ~ ex | en | in
. The latter is typically more convenient, if
there is a large number of exogenous regressors.
Moreover, two further equivalent specification strategies are possible that are
typically less convenient compared to the strategies above. One option is to use
an update formula with a .
in the second part of the formula is used:
y ~ en + ex | . - en + in
. Another option is to use a separate formula
for the instruments (only for backward compatibility with earlier versions):
formula = y ~ en + ex, instruments = ~ in + ex
.
Internally, all specifications are converted to the version with two parts on the right-hand side.
Value
ivreg
returns an object of class "ivreg"
that inherits from
class "lm"
, with the following components:
coefficients |
parameter estimates, from the stage-2 regression. |
residuals |
vector of model residuals. |
residuals1 |
matrix of residuals from the stage-1 regression. |
residuals2 |
vector of residuals from the stage-2 regression. |
fitted.values |
vector of predicted means for the response. |
weights |
either the vector of weights used (if any) or |
offset |
either the offset used (if any) or |
estfun |
a matrix containing the empirical estimating functions. |
n |
number of observations. |
nobs |
number of observations with non-zero weights. |
p |
number of columns in the model matrix x of regressors. |
q |
number of columns in the instrumental variables model matrix z |
rank |
numeric rank of the model matrix for the stage-2 regression. |
df.residual |
residual degrees of freedom for fitted model. |
cov.unscaled |
unscaled covariance matrix for the coefficients. |
sigma |
residual standard deviation. |
qr |
QR decomposition for the stage-2 regression. |
qr1 |
QR decomposition for the stage-1 regression. |
rank1 |
numeric rank of the model matrix for the stage-1 regression. |
coefficients1 |
matrix of coefficients from the stage-1 regression. |
df.residual1 |
residual degrees of freedom for the stage-1 regression. |
exogenous |
columns of the |
endogenous |
columns of the |
instruments |
columns of the |
method |
the method used for the stage 1 and 2 regressions, one of |
rweights |
a matrix of robustness weights with columns for each of the stage-1
regressions and for the stage-2 regression (in the last column) if the fitting method is
|
hatvalues |
a matrix of hatvalues. For |
df.residual |
residual degrees of freedom for fitted model. |
call |
the original function call. |
formula |
the model formula. |
na.action |
function applied to missing values in the model fit. |
terms |
a list with elements |
levels |
levels of the categorical regressors. |
contrasts |
the contrasts used for categorical regressors. |
model |
the full model frame (if |
y |
the response vector (if |
x |
a list with elements |
References
Greene, W.H. (2003) Econometric Analysis, 5th ed., Upper Saddle River: Prentice Hall.
See Also
ivreg.fit
, ivregDiagnostics
, ivregMethods
,
lm
, lm.fit
Examples
## data
data("CigaretteDemand", package = "ivreg")
## model
m <- ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome),
data = CigaretteDemand)
summary(m)
summary(m, vcov = sandwich::sandwich, df = Inf)
## ANOVA
m2 <- update(m, . ~ . - log(rincome) | . - log(rincome))
anova(m, m2)
car::Anova(m)
## same model specified by formula with three-part right-hand side
ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand)
# Robust 2SLS regression
data("Kmenta", package = "ivreg")
Kmenta1 <- Kmenta
Kmenta1[20, "Q"] <- 95 # corrupted data
deq <- ivreg(Q ~ P + D | D + F + A, data=Kmenta) # demand equation, uncorrupted data
deq1 <- ivreg(Q ~ P + D | D + F + A, data=Kmenta1) # standard 2SLS, corrupted data
deq2 <- ivreg(Q ~ P + D | D + F + A, data=Kmenta1, subset=-20) # standard 2SLS, removing bad case
deq3 <- ivreg(Q ~ P + D | D + F + A, data=Kmenta1, method="MM") # 2SLS MM estimation
car::compareCoefs(deq, deq1, deq2, deq3)
round(deq3$rweights, 2) # robustness weights