21/36
Part 4 of 6 · RegressionLearn

Two-way fixed effects give every city and every week its own level

A richer regression gives each city and each week its own level.

def twfe(y, unit, week, D):
    X = np.column_stack([unit == u for u in np.unique(unit)]
                        + [week == w for w in np.unique(week)[1:]]
                        + [D]).astype(float)
    return float(np.linalg.lstsq(X, y, rcond=None)[0][-1])

y, treated, post, week = panel()
city = np.repeat(np.arange(30), 16)
print(f"{twfe(y, city, week, treated * post):.6f}")
print(f"{did_estimate(y, treated, post):.6f}")
Predict

One launch date and a balanced panel. Does two-way fixed effects match the simple difference in differences?

Pick one to see what it prints.
Pick an answer above to see the rest