Jump to ContentJump to Main Navigation
Show Summary Details
More options …

Journal of Econometric Methods

Ed. by Giacomini, Raffaella / Li, Tong

Mathematical Citation Quotient (MCQ) 2018: 0.06

See all formats and pricing
More options …

An Algorithm to Estimate the Two-Way Fixed Effects Model

Paulo Somaini / Frank A. Wolak
Published Online: 2015-03-12 | DOI: https://doi.org/10.1515/jem-2014-0008


We present an algorithm to estimate the two-way fixed effect linear model. The algorithm relies on the Frisch-Waugh-Lovell theorem and applies to ordinary least squares (OLS), two-stage least squares (TSLS) and generalized method of moments (GMM) estimators. The coefficients of interest are computed using the residuals from the projection of all variables on the two sets of fixed effects. Our algorithm has three desirable features. First, it manages memory and computational resources efficiently which speeds up the computation of the estimates. Second, it allows the researcher to estimate multiple specifications using the same set of fixed effects at a very low computational cost. Third, the asymptotic variance of the parameters of interest can be consistently estimated using standard routines on the residualized data.

This article offers supplementary material which is provided at the end of the article.

Keywords: Frisch-Waugh-Lovell theorem; GMM; OLS; panel data; two-way fixed effects


  • Abowd, J. M., F. Kramarz, and D. N. Margolis (1999): “High Wage Workers and High Wage Firms,” Econometrica 67 (2): 251–333.CrossrefGoogle Scholar

  • Arellano, M. 1987. “Computing Robust Standard Errors for Within-Groups Estimators.” Oxford Bulletin of Economics and Statistics 49 (4): 431–434.CrossrefGoogle Scholar

  • Baum, C. F., M. E. Schaffer, and S. Stillman. 2007. “Enhanced Routines for Instrumental Variables/GMM Estimation and Testing.” Stata Journal 7 (4): 465–506.Google Scholar

  • Carneiro, A., P. Guimares, and P. Portugal (2012): “Real Wages and the Business Cycle: Accounting for Worker, Firm, and Job Title Heterogeneity,” American Economic Journal: Macroeconomics 4(2): 133–152.Google Scholar

  • Cornelissen, T. 2008. “The Stata Command Felsdvreg to Fit a Linear Model with Two High-Dimensional Fixed Effects.” Stata Journal 8 (2): 170–189.Google Scholar

  • Correia, S. 2014. “REGHDFE: Stata Module to Perform Linear or Instrumental-Variable Regression Absorbing Any Number of High-Dimensional Fixed Effects,” Statistical Software Components S457874, Boston College Department of Economics.Google Scholar

  • Davis, P. 2002. “Estimating Multi-Way Error Components Models with Unbalanced Data Structures.” Journal of Econometrics 106 (1): 67–95.CrossrefGoogle Scholar

  • Frisch, R., and F. V. Waugh. 1933. “Partial Time Regressions as Compared with Individual Trends.” Econometrica 1 (4): 387–401.CrossrefGoogle Scholar

  • Gaure, S. 2013a. “Lfe: Fitting Linear Models with Multiple Factors with Many Levels.” The R Journal 5(2): 104–116.Google Scholar

  • Gaure, S. 2013b. “OLS with Multiple High Dimensional Category Variables.” Computational Statistics & Data Analysis 66: 8–18.CrossrefWeb of ScienceGoogle Scholar

  • Giles, D. E. A. 1984. “Instrumental Variables Regressions Involving Seasonal Data.” Economics Letters 14 (4): 339–343.CrossrefGoogle Scholar

  • Guimaraes, P. 2009. “REG2HDFE: Stata Module to Estimate a Linear Regression Model with two High Dimensional Fixed Effects,” Statistical Software Components S457101, Boston College Department of Economics.Google Scholar

  • Guimaraes, P., and P. Portugal. 2010. “A Simple Feasible Procedure to Fit Models with High-Dimensional Fixed Effects.” Stata Journal 10 (4): 628–649.Google Scholar

  • Hayashi, F. 2000. Econometrics. Princeton: Princeton University Press.Google Scholar

  • Lovell, M. C. 1963. “Seasonal Adjustment of Economic Time Series and Multiple Regression Analysis.” Journal of the American Statistical Association 58 (304): 993–1010.CrossrefGoogle Scholar

  • Lovell, M. C. 2008. “A Simple Proof of the FWL Theorem.” The Journal of Economic Education 39 (1): 88–91.CrossrefGoogle Scholar

  • Ouazad, A. 2008. “A2REG: Stata Module to Estimate Models with Two Fixed Effects,” Statistical Software Components S456942, Boston College, Department of Economics.Google Scholar

  • Stock, J. H., and M. W. Watson. 2008. “Heteroskedasticity-Robust Standard Errors for Fixed Effects Panel Data Regression.” Econometrica 76 (1): 155–174.Web of ScienceCrossrefGoogle Scholar

  • Wansbeek, T., and A. Kapteyn. 1989. “Estimation of the Error-Components Model with Incomplete Panels.” Journal of Econometrics 41 (3): 341–361.CrossrefGoogle Scholar

  • Wooldridge, J. M. 2010. Econometric Analysis of Cross Section and Panel Data. 2nd ed. Cambridge, Mass: The MIT Press.Google Scholar

About the article

Corresponding author: Paulo Somaini, Department of Economics, MIT, Cambridge, MA, USA, e-mail:

Published Online: 2015-03-12

Published in Print: 2016-01-01

Citation Information: Journal of Econometric Methods, Volume 5, Issue 1, Pages 143–152, ISSN (Online) 2156-6674, ISSN (Print) 2194-6345, DOI: https://doi.org/10.1515/jem-2014-0008.

Export Citation

©2016 by De Gruyter.Get Permission

Supplementary Article Materials

Citing Articles

Here you can find all Crossref-listed publications in which this article is cited. If you would like to receive automatic email messages as soon as this article is cited in other publications, simply activate the “Citation Alert” on the top of this page.

Haiyan Song, Karen Xie, Jinah Park, and Wei Chen
Annals of Tourism Research, 2020, Volume 80, Page 102820
Samuel A. Kleiner
Journal of Public Economics, 2019, Volume 175, Page 94
Frank R. Lichtenberg
Journal of Demographic Economics, 2018, Volume 84, Number 3, Page 309
Futoshi Narita and Rujun Yin
IMF Working Papers, 2018, Volume 18, Number 286, Page 1

Comments (0)

Please log in or register to comment.
Log in