Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing the value of the intercept calculated by the function lm, with that obtained with the function lfe::getfe #31

Open
sciabolazza opened this issue Jul 17, 2020 · 0 comments

Comments

@sciabolazza
Copy link

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 it is possible to obtain a reliable approximation of the value of the intercept estimated by lm using lfe::getfe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant