An Algorithm to Estimate the Two-Way Fixed Effects Model