Fixed effects regression constant (intercept) using lfe::felm

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Fixed effects regression constant (intercept) using lfe::felm

Valerio Leone Sciabolazza
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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Fixed effects regression constant (intercept) using lfe::felm

Bert Gunter-2
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 <
[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Fixed effects regression constant (intercept) using lfe::felm

Rasmus Liland-3
On 2020-07-09 07:15 -0700, Bert Gunter wrote:

> On Thu, Jul 9, 2020 at 3:09 AM Valerio Leone Sciabolazza <[hidden email]> wrote:
> >
> > 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.
> >
> > 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.
>
> 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.
Valerio,

these are such interesting questions.  

Rememeber to post a follow-up of your
findings here and on SO if you are able
to solve this.

V

r

--
 _________________________________________
/ Difficulty                              \
|                                         |
| Practice no-action; Attend to           |
| do-nothing; Taste the flavorless,       |
| Magnify the small, Multiply the few,    |
| Return love for hate. Deal with the     |
| difficult while it is yet easy; Deal    |
| with the great while it is yet small;   |
| The difficult develops naturally from   |
| the easy, And the great from the small; |
| So the sage, by dealing with the small, |
| Achieves the great. Who finds it easy   |
| to promise finds it hard to be trusted; |
| Who takes things lightly finds things   |
| difficult; The sage recognizes          |
| difficulty, and so has none.            |
|                                         |
\ -- Lao Tse, "Tao Te Ching"              /
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

______________________________________________
[hidden email] 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.

signature.asc (849 bytes) Download Attachment