[R] Fixed effects regression constant (intercept) using lfe::felm
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Thu Jul 9 16:15:05 CEST 2020
While you may get lucky here, your experience on SO indicates that you may
do better by contacting the package maintainer (?maintainer) and asking
him/her to refer you to appropriate references, as this sounds like a
statistical methodology query.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Thu, Jul 9, 2020 at 3:09 AM Valerio Leone Sciabolazza <
sciabolazza using gmail.com> wrote:
> Dear list users,
> When calculating a panel data regression with multiple fixed effects
> using the function felm() from the lfe package, no constant term (i.e.
> intercept) is generated in the summary results.
>
> In an old post on stackoverflow [1], someone suggested that it is
> possible to retrieve the value of the intercept by using the function
> lfe::getfe, setting the field "ef" equal to "zm2".
>
> However, I get different results when comparing the value of the
> intercept calculated by the function lm, with that obtained with the
> function lfe::getfe.
>
> Here's a reproducible example:
>
> library(lfe)
>
> # set seed for reproducible example
> set.seed(123)
>
> ## generate independent variables
> x <- rnorm(4000)
> x2 <- rnorm(length(x))
>
> ## create individual and firm ids
> id <- factor(sample(500,length(x),replace=TRUE))
> firm <- factor(sample(300,length(x),replace=TRUE))
>
> ## generate dependent variable
> id.eff <- rlnorm(nlevels(id))
> firm.eff <- rexp(nlevels(firm))
> y <- x + 0.25*x2 + id.eff[id] + firm.eff[firm] + rnorm(length(x))
>
> ## estimate results
> est <- felm(y ~ x + x2 | id + firm)
> est2 <- lm(y ~ x + x2 + id + firm)
>
> ## Compare estimates
> coef(est)
> # x x2
> # 1.017696 0.246784
> coef(est2)[2:3]
> # x x2
> # 1.017696 0.246784
>
> # estimate fixed effects
> fe_est <- getfe(est, ef = "zm2")
>
> ## Compare intercept
> fe_est[grepl("icpt", rownames(fe_est)), ]
> # effect obs comp
> # icpt.1 2.583704 4000 1
> coef(est2)[1]
> # (Intercept)
> # 7.312307
>
> I am wondering if anyone can explain this difference.
> Also, I would like to know if it is possible to obtain a reliable
> approximation of the value of the intercept estimated by lm using
> lfe::getfe.
>
> Best,
> Valerio
>
> P.s.Observe that 3 weeks ago I have posted this question on
> stackoverflow [2] but no one answered.
>
> [1]
> https://stackoverflow.com/questions/49351201/fixed-effects-regression-constant-intercept-using-lfe-felm-in-r
> [2]
> https://stackoverflow.com/questions/62497705/estimate-of-constant-term-using-r-felmlfe-package-and-differences-with-stats
>
> Valerio Leone Sciabolazza, Ph.D.
> Department of Business and Economics
> University of Naples, Parthenope.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list