rfixest

Custom coefficient format for specific variable in fixest etable


I'm wondering if there's a way I can format the coefficient reported in etable in a customized way.

For example, in the below regression

library(fixest)
feols(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width | Species, iris)
model_fit = feols(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width | Species, iris)
etable(model_fit)

                       model_fit
Dependent Var.:     Sepal.Length
                                
Sepal.Width     0.4959. (0.1206)
Petal.Length    0.8292* (0.0970)
Petal.Width     -0.3152 (0.1096)
Fixed-Effects:  ----------------
Species                      Yes
_______________ ________________
S.E.: Clustered      by: Species
Observations                 150
R2                       0.86731
Within R2                0.65201
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

I would like to multiply by 100 only to the coefficient of Sepal.Width for reporting and write a separate note for the adjustment, so that the etable report looks like

                       model_fit
Dependent Var.:     Sepal.Length
                                
Sepal.Width     49.59 (0.1206)
Petal.Length    0.8292* (0.0970)
Petal.Width     -0.3152 (0.1096)
Fixed-Effects:  ----------------
Species                      Yes
_______________ ________________
S.E.: Clustered      by: Species
Observations                 150
R2                       0.86731
Within R2                0.65201
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Is there a handy way to achieve this in fixest etable?

Scaling Sepal.Width column and re-running the regression is the least preferable option for me.

Thank you.


Solution

  • You could do this:

    1. Create a helper function that takes as x one of the string entries in the object returned by etable(model_fit)$model_fit and uses a regular expression to extract the coeficient, multiply by m=100, and pastes it back into the original string x
    f <- function(x,m=100) {
      coef = regmatches(x,regexec("^-?\\d+[.]?\\d+",x,perl=T))[[1]]
      paste0(as.numeric(coef)*m, gsub(coef,"",x))
    }
    
    1. assign etable(model_fit) to an object, k
    k = etable(model_fit)
    
    1. Now, use f() to change one a value in k$model_fit
    k$model_fit[3] <- f(k$model_fit[3])
    print(k)
    
                           model_fit
    Dependent Var.:     Sepal.Length
                                    
    Sepal.Width      49.59. (0.1206)
    Petal.Length    0.8292* (0.0970)
    Petal.Width     -0.3152 (0.1096)
    Fixed-Effects:  ----------------
    Species                      Yes
    _______________ ________________
    S.E.: Clustered      by: Species
    Observations                 150
    R2                       0.86731
    Within R2                0.65201
    ---
    Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1