# ivreg

##### Instrumental-Variable Regression by 2SLS

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.

- Keywords
- regression

##### Usage

```
ivreg(
formula,
instruments,
data,
subset,
na.action,
weights,
offset,
contrasts = NULL,
model = TRUE,
y = TRUE,
x = FALSE,
...
)
```

##### Arguments

- formula, instruments
formula specification(s) of the regression relationship and the instruments. Either

`instruments`

is missing and`formula`

has three parts as in`y ~ x1 + x2 | z1 + z2 + z3`

(recommended) or`formula`

is`y ~ x1 + x2`

and`instruments`

is a one-sided formula`~ z1 + z2 + z3`

(only for backward compatibility).- data
an optional data frame containing the variables in the model. By default the variables are taken from the environment of the

`formula`

.- 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

`NA`

s. The default is set by the`na.action`

option.- 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

`contrasts.arg`

of`model.matrix.default`

.- model, x, y
logicals. If

`TRUE`

the corresponding components of the fit (the model frame, the model matrices, the response) are returned. These components are necessary for computing regression diagnostics.- …
further arguments passed to

`ivreg.fit`

.

##### 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
diagnotics, 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 ~ ex +
en | ex + in
```

. Equivalently, this can be specified as ```
y ~ ex + en | .
- en + in
```

, i.e., by providing an update formula with a `.`

in the
second part of the formula. The latter is typically more convenient, if
there is a large number of exogenous regressors.

##### Value

`ivreg`

returns an object of class `"ivreg"`

that inherits from
class `"lm"`

, with the following components:

parameter estimates, from the stage-2 regression.

vector of model residuals.

matrix of residuals from the stage-1 regression.

vector of residuals from the stage-2 regression.

vector of predicted means for the response.

either the vector of weights used (if any) or `NULL`

(if none).

either the offset used (if any) or `NULL`

(if none).

a matrix containing the empirical estimating functions.

number of observations.

number of observations with non-zero weights.

number of columns in the model matrix x of regressors.

number of columns in the instrumental variables model matrix z

numeric rank of the model matrix for the stage-2 regression.

residual degrees of freedom for fitted model.

unscaled covariance matrix for the coefficients.

residual standard deviation.

QR decomposition for the stage-2 regression.

QR decomposition for the stage-1 regression.

numeric rank of the model matrix for the stage-1 regression.

matrix of coefficients from the stage-1 regression.

residual degrees of freedom for fitted model.

the original function call.

the model formula.

function applied to missing values in the model fit.

a list with elements `"regressors"`

and `"instruments"`

containing the terms objects for the respective components.

levels of the categorical regressors.

the contrasts used for categorical regressors.

the full model frame (if `model = TRUE`

).

the response vector (if `y = TRUE`

).

a list with elements `"regressors"`

, `"instruments"`

, `"projected"`

,
containing the model matrices from the respective components (if `x = TRUE`

).
`"projected"`

is the matrix of regressors projected on the image of the instruments.

##### References

Greene, W.H. (1993) *Econometric Analysis*, 2nd ed., Macmillan.

##### See Also

##### Examples

```
# NOT RUN {
## 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)
# }
```

*Documentation reproduced from package ivreg, version 0.5-0, License: GPL (>= 2)*