The goal of this package is to provide users the ability to easily replicate STATA regressions in R. Particularly, this package provides the reg function, inspired by STATA's reg command. This function allows users to quickly run regressions with robust or clustered standard errors and returns results which match those of STATA. This document demonstrates how to use regr.

Data

This example uses test data from Petersen (2006). Petersen performs the following analyses on this data:

  1. Standard OLS (reg y x)
  2. Robust standard errors: (reg y x, robust)
  3. Cluster standard errors by firm (reg y x, cluster(firmid))
  4. Cluster standard errors by year (reg y x, cluster(year))
  5. Cluster standard errors by firm and year (reg y x, cluster(firmid, year))

Petersen provides the results to these analyses using STATA here. We will replicate these analyses in turn to demonstrate the use of regr.

Example Regressions

First, we load the data.

library(regr)
data("panel_data")

Now, we can run the regressions.

1. Basic OLS

reg(y ~ x, panel_data)

2. Robust standard errors

reg(y ~ x, panel_data, robust = TRUE)

3. Cluster standard errors by firm

reg(y ~ x, panel_data, cluster = "firmid")

4. Cluster standard errors by year

reg(y ~ x, panel_data, cluster = "year")

5. Cluster standard errors by both firm and year

reg(y ~ x, panel_data, cluster = c("firmid", "year"))


joevanderlans/regr documentation built on May 12, 2019, 2:02 p.m.