5

Does anyone know if there is a package that would run Fama-MacBeth regressions in R and calculate the standard errors? I am aware of the sandwich package and its ability to estimate Newey-West standard errors, as well as providing functions for clustering. However, I have not seen anything with respect to Fama-MacBeth.

landroni
  • 2,902
  • 1
  • 32
  • 39
Alex
  • 19,533
  • 37
  • 126
  • 195
  • 3
    `library("sos"); findFn("macbeth")` finds nothing, but `findFn("fama")` gets a few hits in finance-related packages. – Ben Bolker Apr 05 '12 at 19:14

1 Answers1

13

The plm package can estimate Fama-MacBeth regressions and SEs.

require(foreign)
require(plm)
require(lmtest)
test <- read.dta("http://www.kellogg.northwestern.edu/faculty/petersen/htm/papers/se/test_data.dta")
fpmg <- pmg(y~x, test, index=c("year","firmid")) ##Fama-MacBeth

> ##Fama-MacBeth
> coeftest(fpmg)

t test of coefficients:

            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.031278   0.023356  1.3392   0.1806    
x           1.035586   0.033342 31.0599   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

However note that this method works only if your data can be coerced to a pdata.frame. (It will fail if you have "duplicate couples (time-id)".)

For further details see:

landroni
  • 2,902
  • 1
  • 32
  • 39
  • in the example coeftest(fpmg) does not handle double-clustered standard errors. Please show how to do it for fpmg. http://stackoverflow.com/questions/37441230/r-no-way-to-get-double-clustered-standard-errors-for-an-object-of-class-cpmg – Polar Bear May 27 '16 at 05:50
  • One person wrote that we need to swap N and T and everyone is doing it. I see others who have questioned it, but they have been silenced ;) – BBB Jul 31 '17 at 02:08
  • Both orders work on `df.petersen`. `pmg` is supposed to average time series. Sometimes averaging crossections makes theoretical sense. In FM regression: the RHS variable is an index: the same for all ids. Try: `df.petersen2<-data.table(df.petersen); df.petersen2[,`:=`(x=df.petersen2[firmid==1,x]),by="firmid"]`. Then try `summary(pmg(y ~ x, data=df.petersen2, index=c("year","firmid")))`. You will get NAs, as you are running crossections with no RHS variation. `pmg` is not well documented, so I am not sure if it does a proper FM regression, but `index=c("firmid","year"))` produces an estimate. – BBB Jul 31 '17 at 02:21
  • Looking further into this: `pmg` runs just one set of regressions and then takes averages. (not two sets of regressions) So one should populate x with beta estimates from the first FM regression and then use `pmg` on crosssections. For averaging crossections one should use `index=c("year","firmid")`, NB: with this approach errors in estimating betas are lost. – BBB Jul 31 '17 at 03:35