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 baseRpackagestats. The callsummary(lm(y ~ x1 + x2, data = mydata))produces output most similar toreg y x1 x2in Stata. -
lfe- Linear Fixed Effects models. In addition to efficiently handling high-dimension fixed effects, the workhorse functionfelmalso supports instrumental variables and clustered standard errors. As it improveslmby incorporating features common to many econometric analyses,felmis 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
yis the dependent variable,w1andw2are exogenous continuous covariates,f1andf2are categorical variables that are projected out as fixed effects,x1is an endogenous independent variable that is instrumented using exogenousz1, andf3is 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 isivregfor instrumental variables estimation using 2SLS. -
plm- Panel Linear models. I have found this package to be a bit less flexible thanlfebut I have admittedly little experience with it.
knitr- Dynamic documentation tool. Rather than copying and pastingRoutput into a document,knitrand associated tools such asRMarkdownandSweaveprovide a framework in which one can mixRcode 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 ofstargazerbut also the common process of summarizing regression results in general.broomandxtable- Occasianally I find thatstargazeris not flexible to generate the type of summary I need. The next step is to use tools such asbroomto extract estimates from fitted models andxtableto convertRdata.frames to LaTeX tables.