Skip to contents

Functions to perform stepwise estimations in fixest models.

Usage

sw(...)

csw(...)

sw0(...)

csw0(...)

mvsw(...)

Arguments

...

Represents formula variables to be added in a stepwise fashion to an estimation.

Details

To include multiple independent variables, you need to use the stepwise functions. There are 5 stepwise functions: sw, sw0, csw, csw0 and mvsw. Let's explain that.

Assume you have the following formula: fml = y ~ x1 + sw(x2, x3). The stepwise function sw will estimate the following two models: y ~ x1 + x2 and y ~ x1 + x3. That is, each element in sw() is sequentially, and separately, added to the formula. Would have you used sw0 in lieu of sw, then the model y ~ x1 would also have been estimated. The 0 in the name implies that the model without any stepwise element will also be estimated.

Finally, the prefix c means cumulative: each stepwise element is added to the next. That is, fml = y ~ x1 + csw(x2, x3) would lead to the following models y ~ x1 + x2 and y ~ x1 + x2 + x3. The 0 has the same meaning and would also lead to the model without the stepwise elements to be estimated: in other words, fml = y ~ x1 + csw0(x2, x3) leads to the following three models: y ~ x1, y ~ x1 + x2 and y ~ x1 + x2 + x3.

The last stepwise function, mvsw, refers to 'multiverse' stepwise. It will estimate as many models as there are unique combinations of stepwise variables. For example fml = y ~ x1 + mvsw(x2, x3) will estimate y ~ x1, y ~ x1 + x2, y ~ x1 + x3, y ~ x1 + x2 + x3. Beware that the number of estimations grows pretty fast (2^n, with n the number of stewise variables)!

Examples


base = setNames(iris, c("y", "x1", "x2", "x3", "species"))

# Regular stepwise
feols(y ~ sw(x1, x2, x3), base)
#>                               x.1                x.2                x.3
#> Dependent Var.:                 y                  y                  y
#>                                                                        
#> Constant        6.526*** (0.4789)  4.307*** (0.0784)  4.778*** (0.0729)
#> x1               -0.2234 (0.1551)                                      
#> x2                                0.4089*** (0.0189)                   
#> x3                                                   0.8886*** (0.0514)
#> _______________ _________________ __________________ __________________
#> S.E. type                     IID                IID                IID
#> Observations                  150                150                150
#> R2                        0.01382            0.75995            0.66903
#> Adj. R2                   0.00716            0.75833            0.66679
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

# Cumulative stepwise
feols(y ~ csw(x1, x2, x3), base)
#>                               x.1                x.2                 x.3
#> Dependent Var.:                 y                  y                   y
#>                                                                         
#> Constant        6.526*** (0.4789)  2.249*** (0.2480)   1.856*** (0.2508)
#> x1               -0.2234 (0.1551) 0.5955*** (0.0693)  0.6508*** (0.0667)
#> x2                                0.4719*** (0.0171)  0.7091*** (0.0567)
#> x3                                                   -0.5565*** (0.1275)
#> _______________ _________________ __________________ ___________________
#> S.E. type                     IID                IID                 IID
#> Observations                  150                150                 150
#> R2                        0.01382            0.84018             0.85861
#> Adj. R2                   0.00716            0.83800             0.85571
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

# Using the 0
feols(y ~ x1 + x2 + sw0(x3), base)
#>                                x.1                 x.2
#> Dependent Var.:                  y                   y
#>                                                       
#> Constant         2.249*** (0.2480)   1.856*** (0.2508)
#> x1              0.5955*** (0.0693)  0.6508*** (0.0667)
#> x2              0.4719*** (0.0171)  0.7091*** (0.0567)
#> x3                                 -0.5565*** (0.1275)
#> _______________ __________________ ___________________
#> S.E. type                      IID                 IID
#> Observations                   150                 150
#> R2                         0.84018             0.85861
#> Adj. R2                    0.83800             0.85571
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

# Multiverse stepwise
feols(y ~ x1 + mvsw(x2, x3), base)
#>                               x.1                x.2                x.3
#> Dependent Var.:                 y                  y                  y
#>                                                                        
#> Constant        6.526*** (0.4789)  2.249*** (0.2480)  3.457*** (0.3092)
#> x1               -0.2234 (0.1551) 0.5955*** (0.0693) 0.3991*** (0.0911)
#> x2                                0.4719*** (0.0171)                   
#> x3                                                   0.9721*** (0.0521)
#> _______________ _________________ __________________ __________________
#> S.E. type                     IID                IID                IID
#> Observations                  150                150                150
#> R2                        0.01382            0.84018            0.70724
#> Adj. R2                   0.00716            0.83800            0.70325
#> 
#>                                 x.4
#> Dependent Var.:                   y
#>                                    
#> Constant          1.856*** (0.2508)
#> x1               0.6508*** (0.0667)
#> x2               0.7091*** (0.0567)
#> x3              -0.5565*** (0.1275)
#> _______________ ___________________
#> S.E. type                       IID
#> Observations                    150
#> R2                          0.85861
#> Adj. R2                     0.85571
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1