Description Arguments Details Value Methods Source See Also Examples
Instrumental-Variable Regression
model |
the name of a statistical model to estimate. For a list of other supported models and their documentation see: http://docs.zeligproject.org/articles/. |
data |
the name of a data frame containing the variables
referenced in the formula or a list of multiply imputed data frames
each having the same variable names and row numbers (created by
|
by |
a factor variable contained in |
cite |
If is set to 'TRUE' (default), the model citation will be printed to the console. |
formula |
specification(s) of the regression relationship |
instruments |
the instruments. Either |
model, x, y |
logicals. If |
... |
further arguments passed to methods. See also |
Additional parameters avaialable to many models include:
weights: vector of weight values or a name of a variable in the dataset by which to weight the model. For more information see: http://docs.zeligproject.org/articles/weights.html.
bootstrap: logical or numeric. If FALSE
don't use bootstraps to
robustly estimate uncertainty around model parameters due to sampling error.
If an integer is supplied, the number of boostraps to run.
For more information see:
http://docs.zeligproject.org/articles/bootstraps.html.
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 regressors and
z1
, z2
, and z3
are the instruments. 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.
Depending on the class of model selected, zelig
will return
an object with elements including coefficients
, residuals
,
and formula
which may be summarized using
summary(z.out)
or individually extracted using, for example,
coef(z.out)
. See
http://docs.zeligproject.org/articles/getters.html for a list of
functions to extract model components. You can also extract whole fitted
model objects using from_zelig_model
.
zelig(formula, data, model = NULL, ..., weights = NULL, by, bootstrap = FALSE)
The zelig function estimates a variety of statistical models
ivreg
is from Christian Kleiber and Achim Zeileis (2008). Applied
Econometrics with R. New York: Springer-Verlag. ISBN 978-0-387-77316-2. URL
https://CRAN.R-project.org/package=AER
Vignette: http://docs.zeligproject.org/articles/zelig_ivreg.html Fit instrumental-variable regression by two-stage least squares. This is equivalent to direct instrumental-variables estimation when the number of instruments is equal to the number of predictors.
zelig
,
Greene, W. H. (1993) Econometric Analysis, 2nd ed., Macmillan.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | library(Zelig)
library(dplyr) # for the pipe operator %>%
# load and transform data
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)
# log second stage independent variables, as logging internally for ivreg is
# not currently supported
CigarettesSW$log_rprice <- log(CigarettesSW$rprice)
CigarettesSW$log_rincome <- log(CigarettesSW$rincome)
z.out1 <- zelig(log(packs) ~ log_rprice + log_rincome |
log_rincome + tdiff + I(tax/cpi),data = CigarettesSW, subset = year == "1995",model = "ivreg")
summary(z.out1)
library(Zelig)
library(AER) # for sandwich vcov
library(dplyr) # for the pipe operator %>%
# load and transform data
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)
# log second stage independent variables, as logging internally for ivreg is
# not currently supported
CigarettesSW$log_rprice <- log(CigarettesSW$rprice)
CigarettesSW$log_rincome <- log(CigarettesSW$rincome)
# estimate model
z.out1 <- zelig(log(packs) ~ log_rprice + log_rincome |
log_rincome + tdiff + I(tax/cpi),
data = CigarettesSW,
model = "ivreg")
summary(z.out1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.