Vignette: http://docs.zeligproject.org/articles/zelig_ivreg.html

Arguments

formula

specification(s) of the regression relationship

instruments

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. Using instruments is not recommended with zelig.

model, x, y

logicals. If TRUE the corresponding components of the fit (the model frame, the model matrices , the response) are returned.

...

further arguments passed to methods. See also zelig.

Source

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

Details

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.

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.

Methods

zelig(formula, data, model = NULL, ..., weights = NULL, by, bootstrap = FALSE)

The zelig function estimates a variety of statistical models

See also

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

Examples

library(AER) # for sandwich vcov
#> Loading required package: car
#> Loading required package: lmtest
#> Loading required package: zoo
#> #> Attaching package: ‘zoo’
#> The following objects are masked from ‘package:base’: #> #> as.Date, as.Date.numeric
#> Loading required package: sandwich
library(dplyr) # for the pipe operator %>%
#> #> Attaching package: ‘dplyr’
#> The following object is masked from ‘package:car’: #> #> recode
#> The following objects are masked from ‘package:stats’: #> #> filter, lag
#> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union
# 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.61378 -0.07232 0.01435 0.09486 0.37504 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 9.7365 0.5687 17.122 < 2e-16 #> log_rprice -1.2291 0.1552 -7.922 4.94e-12 #> log_rincome 0.2568 0.1434 1.791 0.0765 #> #> Residual standard error: 0.1654 on 93 degrees of freedom #> Multiple R-Squared: 0.5486, Adjusted R-squared: 0.5389 #> Wald test: 39.93 on 2 and 93 DF, p-value: 3.025e-13 #> #> Next step: Use 'setx' method
from_zelig_model(z.out1) %>% summary(vcov = sandwich, df = Inf, diagnostics = TRUE)
#> #> Call: #> `z5$zelig`(formula = formula, data = data, by = by) #> #> Residuals: #> Min 1Q Median 3Q Max #> -0.61378 -0.07232 0.01435 0.09486 0.37504 #> #> Coefficients: #> Estimate Std. Error z value Pr(>|z|) #> (Intercept) 9.7365 0.5060 19.243 < 2e-16 *** #> log_rprice -1.2291 0.1522 -8.078 6.59e-16 *** #> log_rincome 0.2568 0.1503 1.709 0.0874 . #> #> Diagnostic tests: #> df1 df2 statistic p-value #> Weak instruments 2 92 145.502 <2e-16 *** #> Wu-Hausman 1 92 2.204 0.141 #> Sargan 1 NA 0.018 0.893 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> Residual standard error: 0.1654 on Inf degrees of freedom #> Multiple R-Squared: 0.5486, Adjusted R-squared: 0.5389 #> Wald test: 101.5 on 2 DF, p-value: < 2.2e-16 #>
# simulate and plot quantities of interest z.out1 %>% setx() %>% sim() %>% plot()
# ANOVA z.out2 <- zelig(log(packs) ~ log_rprice | tdiff, 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/
anova(from_zelig_model(z.out1), from_zelig_model(z.out2))
#> Analysis of Variance Table #> #> Model 1: log(packs) ~ log_rprice + log_rincome | log_rincome + tdiff + #> I(tax/cpi) #> Model 2: log(packs) ~ log_rprice | tdiff #> Res.Df RSS Df Sum of Sq F Pr(>F) #> 1 93 2.5456 #> 2 94 2.6785 -1 -0.13293 3.208 0.07653 . #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1