Instrumental-Variable Regression
formula | a symbolic representation of the model to be
estimated, in the form |
---|---|
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
|
... | additional arguments passed to |
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 |
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
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
.
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.
zelig(formula, data, model = NULL, ..., weights = NULL, by,
bootstrap = FALSE)
The zelig function estimates a variety of statistical models
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.
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")#> Error in eval(substitute(subset), data, env): object 'year' not foundsummary(z.out1)#> Error in summary(z.out1): object 'z.out1' not foundlibrary(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")#> How to cite this model in Zelig: #> Christian Kleiber and Achim Zeileis. 2008. #> ivreg: Instrumental-Variable Regression #> in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau, #> "Zelig: Everyone's Statistical Software," http://zeligproject.org/summary(z.out1)#> Model: #> #> Call: #> z5$zelig(formula = formula, data = data, by = by) #> #> Residuals: #> Min 1Q Median 3Q Max #> -0.6138 -0.0723 0.0144 0.0949 0.3750 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 9.736 0.569 17.12 < 2e-16 #> log_rprice -1.229 0.155 -7.92 4.9e-12 #> log_rincome 0.257 0.143 1.79 0.077 #> #> Residual standard error: 0.165 on 93 degrees of freedom #> Multiple R-Squared: 0.549, Adjusted R-squared: 0.539 #> Wald test: 39.9 on 2 and 93 DF, p-value: 3.02e-13 #> #> Next step: Use 'setx' method