Skip to content

Support cluster argument to feols() #10

@SebKrantz

Description

@SebKrantz
options(fastverse.styling = FALSE)
library(fastverse)
#> -- Attaching packages --------------------------------------- fastverse 0.3.2 --
#> v data.table 1.14.8     v kit        0.0.13
#> v magrittr   2.0.3      v collapse   2.0.7
fastverse_extend(fixest, wildrwolf)
#> -- Attaching extension packages ----------------------------- fastverse 0.3.2 --
#> Warning: package 'fixest' was built under R version 4.3.1
#> v fixest    0.11.2     v wildrwolf 0.6.1
#> -- Conflicts ------------------------------------------ fastverse_conflicts() --
#> x fixest::fdim() masks collapse::fdim()
models = feols(c(vs, am) ~ mpg | cyl, mtcars, cluster = "carb")
rwolf(models = models, param = "mpg", B = 9999)
#>   |                                                                              |                                                                      |   0%
#> Error in formula.character(clustid): invalid formula "carb": not a call

models = feols(c(vs, am) ~ mpg | cyl, mtcars, cluster = ~carb)
rwolf(models = models, param = "mpg", B = 9999)
#>   |                                                                              |                                                                      |   0%
#> Warning: Please note that the seeding behavior for random number generation for
#> `boottest()` has changed with `fwildclusterboot` version 0.13.
#> 
#> It will no longer be possible to exactly reproduce results produced by versions
#> lower than 0.13.
#> 
#> If your prior results were produced under sufficiently many bootstrap
#> iterations, none of your conclusions will change.  For more details about this
#> change, please read the notes in
#> [news.md](https://cran.r-project.org/web/packages/fwildclusterboot/news/news.html).
#> This warning is displayed once per session.
#> Warning: There are only 64 unique draws from the rademacher distribution for 6 bootstrap
#> clusters. Therefore, B = 64 with full enumeration. Consider using webb weights
#> instead. Further, note that under full enumeration and with B = 64 bootstrap
#> draws, only 2^(#clusters - 1) = 32 distinct t-statistics and p-values can be
#> computed. For a more thorough discussion, see Webb `Reworking wild bootstrap
#> based inference for clustered errors` (2013).
#>   |                                                                              |===================================                                   |  50%
#> Warning: There are only 64 unique draws from the rademacher distribution for 6 bootstrap
#> clusters. Therefore, B = 64 with full enumeration. Consider using webb weights
#> instead. Further, note that under full enumeration and with B = 64 bootstrap
#> draws, only 2^(#clusters - 1) = 32 distinct t-statistics and p-values can be
#> computed. For a more thorough discussion, see Webb `Reworking wild bootstrap
#> based inference for clustered errors` (2013).
#>   |                                                                              |======================================================================| 100%
#>   model     Estimate Std. Error    t value    Pr(>|t|) RW Pr(>|t|)
#> 1     1 -0.006000719 0.01009511 -0.5944186   0.5781065   0.9692308
#> 2     2   0.04767382 0.01039968   4.584163 0.005924984   0.2000000

models = feols(c(vs, am) ~ mpg | cyl, mtcars, cluster = as.character(mtcars$carb))
rwolf(models = models, param = "mpg", B = 9999)
#>   |                                                                              |                                                                      |   0%
#> Error in terms.formula(formula, data = data): invalid model formula in ExtractVars

Created on 2023-12-12 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions