This note summarizes several tools for traditional econometric analysis using R
. The CRAN Task View - Econometrics provides a very comprehensive overview of available econometrics packages in R
. Rather the duplicate this resource, I will highlight several functions and tools that accommodate 95% of my econometric analyses.
-
stats::lm
- the standard OLS routine included in the baseR
packagestats
. The callsummary(lm(y ~ x1 + x2, data = mydata))
produces output most similar toreg y x1 x2
in Stata. -
lfe
- Linear Fixed Effects models. In addition to efficiently handling high-dimension fixed effects, the workhorse functionfelm
also supports instrumental variables and clustered standard errors. As it improveslm
by incorporating features common to many econometric analyses,felm
is my preferred tool for linear models. To illustrate typical usage, one might summarize the results of a linear model withsummary(felm(y ~ w1 + w2 | f1 + f2 | (x1 ~ z1) | f3, data = mydata))
where
y
is the dependent variable,w1
andw2
are exogenous continuous covariates,f1
andf2
are categorical variables that are projected out as fixed effects,x1
is an endogenous independent variable that is instrumented using exogenousz1
, andf3
is the categorical variable by which standard errors are clustered. -
AER
- this package includes many functions and datasets to accompany the excellent book by Christian Kleiber and Achim Zeileis, Applied Econometrics with R (2008), which I highly recommend reading. One notable function isivreg
for instrumental variables estimation using 2SLS. -
plm
- Panel Linear models. I have found this package to be a bit less flexible thanlfe
but I have admittedly little experience with it.
knitr
- Dynamic documentation tool. Rather than copying and pastingR
output into a document,knitr
and associated tools such asRMarkdown
andSweave
provide a framework in which one can mixR
code and output with the final output document. A much better introduction to the package and countless examples can be seen here.stargazer
- easily summarizes regression models in tables. In addition to the package documentation, I cannot recommend the phenomenal cheat sheet by Jake Russ, which not only illustrates the features ofstargazer
but also the common process of summarizing regression results in general.broom
andxtable
- Occasianally I find thatstargazer
is not flexible to generate the type of summary I need. The next step is to use tools such asbroom
to extract estimates from fitted models andxtable
to convertR
data.frames to LaTeX tables.