lrberge / fixest

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

Reset global options changed in `setFixest_*`? #460

Closed etiennebacher closed 5 months ago

etiennebacher commented 6 months ago

The setFixest_* functions are extremely helpful to avoid duplicating the same options again and again. However, sometimes I want to remove some general options that I wrongly put in setFixest_* earlier. The problem is that (if I'm not mistaken) the only way to do so is to restart the session and set the correct options. This can be annoying because I would need to redo some computations.

Is it possible to have something like fixest::reset_options(type = c("table", "coefplot", ...)) where one can reset all options set in setFixest_* to their default?

As always, thanks for this amazing package.


Small example:

library(fixest)

###
### I mistakenly set some `style_df` options
###
setFixest_etable(
  style.df = style.df(
    fixef.suffix = " fixed effect",
    yesNo = "Yes"
  )
)

res <- feols(Sepal.Length ~ Sepal.Width | Species, iris)

###
### I realize this is not as I want
###
etable(res)
#>                                    res
#> Dependent Var.:           Sepal.Length
#>                                       
#> Sepal.Width          0.8036** (0.0714)
#> Fixed-Effects:       -----------------
#> Species fixed effect               Yes
#> ____________________ _________________
#> S.E.: Clustered            by: Species
#> Observations                       150
#> R2                             0.72591
#> Within R2                      0.28115
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

setFixest_etable()

# 
### This didn't reset the options for `fixef.suffix`
#
etable(res)
#>                                    res
#> Dependent Var.:           Sepal.Length
#>                                       
#> Sepal.Width          0.8036** (0.0714)
#> Fixed-Effects:       -----------------
#> Species fixed effect               Yes
#> ____________________ _________________
#> S.E.: Clustered            by: Species
#> Observations                       150
#> R2                             0.72591
#> Within R2                      0.28115
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lrberge commented 5 months ago

Hi Etienne, actually in most setFixest_* functions, there is the argument reset:

setFixest_etable(
  style.df = style.df(
    fixef.suffix = " fixed effect",
    yesNo = "Yes"
  )
)

res = feols(Sepal.Length ~ Sepal.Width | Species, iris)

etable(res)
#> the previous table

# getting the default style back
setFixest_etable(reset = TRUE)

etable(res)
#>                               res
#> Dependent Var.:      Sepal.Length
#> 
#> Sepal.Width     0.8036** (0.0714)
#> Fixed-Effects:  -----------------
#> Species                       Yes
#> _______________ _________________
#> S.E.: Clustered       by: Species
#> Observations                  150
#> R2                        0.72591
#> Within R2                 0.28115
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

# You can also add options when using reset
setFixest_etable(reset = TRUE, digits = 2)

etable(res)
#>                           res
#> Dependent Var.:  Sepal.Length
#> 
#> Sepal.Width     0.80** (0.07)
#> Fixed-Effects:  -------------
#> Species                   Yes
#> _______________ _____________
#> S.E.: Clustered   by: Species
#> Observations              150
#> R2                    0.72591
#> Within R2             0.28115
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Isn't that enough for the purpose?

etiennebacher commented 5 months ago

Well I guess I should just improve my RTFM skills :sweat_smile: thanks!