lrberge / fixest

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

feols() no longer dependent variables in a list within list of samples #404

Closed djn34 closed 5 months ago

djn34 commented 1 year ago

Hello,

The feols() function recently started storing results in a different list format. For a line of code like this:

tsreg[["age"]] <- df %>%feols(.[y] ~ .[xb], weights = ~wt, cluster = "zip", split = "age_group")

We used to receive a list that could be indexed like this to receive "nobs":

tsreg$age$[sample label]$[y element]$nobs

So we had:

  1. main list ("tsreg")
  2. specified list within that list ("age")
  3. list of samples ("[sample label]")
  4. list of y-elements within each sample ("[y element]")
  5. stored information for the model specified in steps 1:4

Filled out with real labels, this could be:

tsreg$age$18-24$used_med$nobs

However, something changed recently, and this is now how I have to index that same piece of information:

tsreg$age$`sample.var: age_group; sample: 18-24; lhs: used_med`$nobs

This has complicated the way that we pull values from the results to store in tables. It used to work really well when I could write a code that specified everything but the sample, which I could turn into a variable.

Is there a way to store the data in a list again so that "sample" and "lhs" were each their own elements that could be referenced? This is how feols() used to store data for me, so I'm hoping there is just a setting within the code that I can change.

Thank you!

lrberge commented 5 months ago

Hi, indeed there was a breaking change to a much more consistent format. Now the fixest_multi object is simply a plain list, hence it's much easier to apply stuff to.

The recommended way to select elements is with the dedicated [.fixest_multi method, detailed here.

Here's an example that should cover your use case:

base = setNames(iris, c("y1", "y2", "x1", "x2", "species"))
est = feols(c(y1, y2) ~ x1, base, fsplit = ~species)

est[lhs = "y1", sample = "setosa", drop = TRUE]$nobs
#> [1] 50