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.
Fama MacBeth standard errors in R
Asked Answered
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:
in the example coeftest(fpmg) does not handle double-clustered standard errors. Please show how to do it for fpmg. #37441730 –
Elison
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 ;) –
Henryson
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. –
Henryson 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. –
Henryson © 2022 - 2024 — McMap. All rights reserved.
library("sos"); findFn("macbeth")
finds nothing, butfindFn("fama")
gets a few hits in finance-related packages. – Veolaver