lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
361 stars 59 forks source link

fixest::d() not working even though fixest::panel was called #500

Closed kmfrick closed 1 month ago

kmfrick commented 1 month ago

Hello Laurent,

first of all, my compliments for all your work on and dedication to fixest :)

Here's a bug report on what I understand is unexpected behavior on fixest::d.

MWE:

set.seed(1)
N = 15
TT = 10
NT = N * TT
data <- data.frame(y = rnorm(NT), i = rep(1:N, TT), t = as.vector(sapply(1:TT, function(x) rep(x, N))))
data <- fixest::panel(as.data.table(data), ~i+t)
is.data.table(data)
data[,d_y := fixest::d(y)]

Expected outcome: d_y gets created with the first-differenced value for d.

Outcome:

Error in l(x, lag, fill) : 
  You can use l() or f() only when the data set is of class 'fixest_panel', you can use function panel() to set it.

Version of fixest:

[Package fixest version 0.12.0 [Index](http://127.0.0.1:10405/help/library/fixest/html/00Index.html)]

Version of data_table:

data.table 1.15.4 using 1 threads (see ?getDTthreads).  Latest news: r-datatable.com
**********
This installation of data.table has not detected OpenMP support. It should still work but in single-threaded mode.
This is a Mac. Please read https://mac.r-project.org/openmp/. Please engage with Apple and ask them for support. Check r-datatable.com for updates, and our Mac instructions here: https://github.com/Rdatatable/data.table/wiki/Installation. After several years of many reports of installation problems on Mac, it's time to gingerly point out that there have been no similar problems on Windows or Linux.
**********

Please let me know if there's any further information you may need.

lrberge commented 1 month ago

Thanks Kevin! That's a peculiar bug (happened when the name of the data set was equal to a function).

Now the function is more robust (fe95063). Thanks for reporting.