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

Centered variables not returned in IV regression #94

Closed
amarbler opened this issue Jan 19, 2021 · 1 comment
Closed

Centered variables not returned in IV regression #94

amarbler opened this issue Jan 19, 2021 · 1 comment

Comments

@amarbler
Copy link

Hi Laurent,

Thanks for this great package and your huge efforts!

I just wanted to let you know that I stumbled upon a small bug: feols(..., demeaned = TRUE) does not return the centered variables in the case of IV regressions, e.g.:

library(fixest)
library(lfe)
library(data.table)

set.seed(1111)

x <- rnorm(1000)
x2 <- rnorm(length(x))
id <- factor(sample(20,length(x),replace=TRUE))
firm <- factor(sample(13,length(x),replace=TRUE))
id.eff <- rnorm(nlevels(id))
firm.eff <- rnorm(nlevels(firm))
u <- rnorm(length(x))
y <- x + 0.5*x2 + id.eff[id] + firm.eff[firm] + u
x3 <- rnorm(length(x))
Q <- 0.3*x3 + 0.01*x + 0.02*x2 + id.eff[id]  - 0.3*y + rnorm(length(x),sd=0.3)
y <- y + Q

df = data.table(id, firm, y, x, x2, x3, Q)

iv_feols <- fixest::feols(y ~ x + x2 | id + firm | Q ~ x3, demeaned = TRUE, data = df)

iv_feols$X_demeaned; iv_feols$y_demeaned
NULL
NULL

sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 10 (buster)

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] backports_1.2.1   data.table_1.13.6 lfe_2.8-6         Matrix_1.2-18
[5] fixest_0.8.1

loaded via a namespace (and not attached):
 [1] zoo_1.8-8           compiler_3.5.2      parallel_3.5.2
 [4] sandwich_3.0-0      dreamerr_1.2.3      Rcpp_1.0.6
 [7] nlme_3.1-151        grid_3.5.2          Formula_1.2-4
[10] xtable_1.8-4        numDeriv_2016.8-1.1 lattice_0.20-41

Cheers
Alex

@lrberge
Copy link
Owner

lrberge commented Jan 22, 2021

Thanks! I'll deal with that when I can!

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

2 participants