fixest R Package Documentation

repository·master·Indexed 19 days ago

https://github.com/lrberge/fixest

A high-performance R package for fast and flexible econometric estimations, including OLS, IV, GLM, ML, and Difference-in-Differences models. Optimized for large datasets with complex fixed-effects structures, it provides tools such as feols() for estimations, sw0() for stepwise fixed-effects, etable() for result exporting, and coefplot() for coefficient visualization.

Tokens
945
Snippets
5
Records
5
Agent score
16%

What's inside fixest

  1. Install fixest

    master

    You can install fixest from CRAN for the stable version, or from the fastverse R-universe to get the latest stable development release.

    From CRAN

    install.packages("fixest")

    Latest stable development release

    install.packages("fixest", repos = ropensci = 'https://fastverse.r-universe.dev')
    # To install from CRAN:
    install.packages("fixest")
    
    # To install the latest stable development release:
    install.packages("fixest", repos = ropensci = 'https://fastverse.r-universe.dev')
  2. Visualize coefficients with coefplot()

    master

    You can visualize coefficients using coefplot(). This is particularly useful when you have split your sample by a variable.

    Coefficient Plots for Split Samples

    To split a sample by a variable (e.g., Month) and plot the coefficients:

    # Split the sample by Month
    est_month = feols(Ozone ~ Solar.R + Temp, airquality, split = ~Month)
    
    # Plot coefficients, dropping the Constant from the plot
    coefplot(est_month, drop = "Constant")
    
    # Add a legend manually
    legend("topleft", col = 1:5, lty = 1, lwd = 2, legend = paste0("Month = ", 5:9))
    est_month = feols(Ozone ~ Solar.R + Temp, airquality, split = ~Month)
    coefplot(est_month, drop = "Constant")
    legend("topleft", col = 1:5, lty = 1, lwd = 2, legend = paste0("Month = ", 5:9))
  3. Display and export results with etable()

    master

    The etable() function is used to display results from one or multiple estimations in a clean, tabular format.

    Basic Table

    etable(est_multi)

    Customizing Standard Errors (VCOV)

    Use the vcov argument to change the standard errors. For example, to use clustered standard errors:

    etable(est_multi, vcov = vcov_cluster("Month"))
    # Display multiple results
    etable(est_multi)
    
    # Report results with clustered standard-errors
    etable(est_multi, vcov = vcov_cluster("Month"))
  4. Estimate OLS models with feols()

    master

    The feols() function is used for Ordinary Least Squares (OLS) estimations. It supports a unified syntax for specifying dependent variables, independent variables, and fixed-effects.

    Basic OLS

    To estimate a model without fixed-effects:

    feols(Ozone ~ Solar.R + Temp, airquality)

    OLS with Fixed-Effects

    To include fixed-effects (categorical variables where coefficients are not reported), use the pipe (|) operator in the formula:

    feols(Ozone ~ Solar.R + Temp | Month + Day, airquality)

    In this syntax, Month and Day are treated as fixed-effects.

    # OLS model: feols
    feols(Ozone ~ Solar.R + Temp, airquality)
    
    # Adding fixed-effects
    feols(Ozone ~ Solar.R + Temp | Month + Day, airquality)
  5. Run multiple estimations with stepwise fixed-effects

    master

    You can run multiple estimations simultaneously using the sw0() function within the fixed-effects part of the formula. sw stands for "stepwise" and 0 indicates starting with an empty set of fixed-effects.

    This allows you to compare models with increasing levels of fixed-effects in a single call.

    # Runs two models: one with no fixed-effects and one with Month + Day
    est_multi = feols(Ozone ~ Solar.R + Temp | sw0(Month + Day), airquality)
    # sw0(): 'sw' means "stepwise", '0' means starting with the empty element
    est_multi = feols(Ozone ~ Solar.R + Temp | sw0(Month + Day), airquality)