Search code examples
rregressionfixest

How do I store the estimation sample from a fixest regression to calculate summary statistics?


How do I store the estimation sample from a fixest::feols regression so that I can calculate summary statistics? In Stata this can be done with e(sample), eg. sum y if e(sample) to calculate the mean of the dependent variable on the estimation sample.

From a previous question, I see that obs(model) can be used to store the estimation sample to run further regressions using subset, but I don't see how to use it to calculate summary statistics, because obs(model) returns integers instead of Booleans.


Solution

  • One solution is filtering on the indices of the dataframe:

    df %>% filter(row_number() %in% obs(model))
       %>% summarize(y_mean = mean(y))