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)
#> Standard-errors: IID 
#> Expl. vars.: x1
#>              Estimate Std. Error  t value  Pr(>|t|)    
#> (Intercept)  6.526223   0.478896 13.62763 < 2.2e-16 ***
#> x1          -0.223361   0.155081 -1.44029    0.1519    
#> ---
#> Expl. vars.: x2
#>             Estimate Std. Error t value  Pr(>|t|)    
#> (Intercept) 4.306603   0.078389 54.9389 < 2.2e-16 ***
#> x2          0.408922   0.018891 21.6460 < 2.2e-16 ***
#> ---
#> Expl. vars.: x3
#>             Estimate Std. Error t value  Pr(>|t|)    
#> (Intercept) 4.777629   0.072935 65.5055 < 2.2e-16 ***
#> x3          0.888580   0.051374 17.2965 < 2.2e-16 ***

# Cumulative stepwise
feols(y ~ csw(x1, x2, x3), base)
#> Standard-errors: IID 
#> Expl. vars.: x1
#>              Estimate Std. Error  t value  Pr(>|t|)    
#> (Intercept)  6.526223   0.478896 13.62763 < 2.2e-16 ***
#> x1          -0.223361   0.155081 -1.44029    0.1519    
#> ---
#> Expl. vars.: x1 + x2
#>             Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept) 2.249140   0.247970  9.07022 7.0385e-16 ***
#> x1          0.595525   0.069328  8.58994 1.1633e-14 ***
#> x2          0.471920   0.017118 27.56916  < 2.2e-16 ***
#> ---
#> Expl. vars.: x1 + x2 + x3
#>              Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept)  1.855997   0.250777  7.40098 9.8539e-12 ***
#> x1           0.650837   0.066647  9.76538  < 2.2e-16 ***
#> x2           0.709132   0.056719 12.50248  < 2.2e-16 ***
#> x3          -0.556483   0.127548 -4.36293 2.4129e-05 ***

# Using the 0
feols(y ~ x1 + x2 + sw0(x3), base)
#> Standard-errors: IID 
#> Expl. vars.: x1 + x2
#>             Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept) 2.249140   0.247970  9.07022 7.0385e-16 ***
#> x1          0.595525   0.069328  8.58994 1.1633e-14 ***
#> x2          0.471920   0.017118 27.56916  < 2.2e-16 ***
#> ---
#> Expl. vars.: x1 + x2 + x3
#>              Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept)  1.855997   0.250777  7.40098 9.8539e-12 ***
#> x1           0.650837   0.066647  9.76538  < 2.2e-16 ***
#> x2           0.709132   0.056719 12.50248  < 2.2e-16 ***
#> x3          -0.556483   0.127548 -4.36293 2.4129e-05 ***

# Multiverse stepwise
feols(y ~ x1 + mvsw(x2, x3), base)
#> Standard-errors: IID 
#> Expl. vars.: x1
#>              Estimate Std. Error  t value  Pr(>|t|)    
#> (Intercept)  6.526223   0.478896 13.62763 < 2.2e-16 ***
#> x1          -0.223361   0.155081 -1.44029    0.1519    
#> ---
#> Expl. vars.: x1 + x2
#>             Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept) 2.249140   0.247970  9.07022 7.0385e-16 ***
#> x1          0.595525   0.069328  8.58994 1.1633e-14 ***
#> x2          0.471920   0.017118 27.56916  < 2.2e-16 ***
#> ---
#> Expl. vars.: x1 + x3
#>             Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept) 3.457333   0.309188 11.18199  < 2.2e-16 ***
#> x1          0.399071   0.091110  4.38012 2.2416e-05 ***
#> x3          0.972130   0.052099 18.65937  < 2.2e-16 ***
#> ---
#> Expl. vars.: x1 + x2 + x3
#>              Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept)  1.855997   0.250777  7.40098 9.8539e-12 ***
#> x1           0.650837   0.066647  9.76538  < 2.2e-16 ***
#> x2           0.709132   0.056719 12.50248  < 2.2e-16 ***
#> x3          -0.556483   0.127548 -4.36293 2.4129e-05 ***