Skip to contents

Retrieves the original data set used to estimate a fixest or fixest_multi model. Note that this is the original data set and not the data used for the estimation (i.e. it can have more rows).

Usage

fixest_data(x, sample = "original")

Arguments

x

An object of class fixest or fixest_multi. For example obtained from feols or feglm.

sample

Either "original" (default) or "estimation". If equal to "original", it matches the original data set. If equal to "estimation", the rows of the data set returned matches the observations used for the estimation.

Value

It returns a data.frame equal to the original data set used for the estimation, when the function was called.

If sample = "estimation", only the lines used for the estimation are returned.

In case of a fixest_multi object, it returns the data set of the first estimation object. So in that case it does not make sense to use sample = "estimation" since the samples may be inconsistent across the different estimations.

Examples


base = setNames(iris, c("y", "x1", "x2", "x3", "species"))
base$y[1:5] = NA

est = feols(y ~ x1 + x2, base)
#> NOTE: 5 observations removed because of NA values (LHS: 5).

# the original data set
head(fixest_data(est))
#>     y  x1  x2  x3 species
#> 1  NA 3.5 1.4 0.2  setosa
#> 2  NA 3.0 1.4 0.2  setosa
#> 3  NA 3.2 1.3 0.2  setosa
#> 4  NA 3.1 1.5 0.2  setosa
#> 5  NA 3.6 1.4 0.2  setosa
#> 6 5.4 3.9 1.7 0.4  setosa

# the data set, with only the lines used for the estimation
head(fixest_data(est, sample = "est"))
#>      y  x1  x2  x3 species
#> 6  5.4 3.9 1.7 0.4  setosa
#> 7  4.6 3.4 1.4 0.3  setosa
#> 8  5.0 3.4 1.5 0.2  setosa
#> 9  4.4 2.9 1.4 0.2  setosa
#> 10 4.9 3.1 1.5 0.1  setosa
#> 11 5.4 3.7 1.5 0.2  setosa