This paper develops a framework for estimation and inference to analyze the effect of a policy or treatment in settings with treatment-effect heterogeneity and variation in treatment timing. We propose a two-stage difference-in-differences (2SDD) estimator that compares treated and untreated outcomes after removing group and period effects identified using untreated observations. Our regression-based approach enables us to conduct inference within a conventional GMM asymptotic framework. It easily facilitates extensions such as dynamic treatment effects, triple differences, continuous treatments, time-varying controls, and violations of parallel trends. Simulations of randomly generated placebo laws in state-level wage data demonstrate that 2SDD has rejection rates that are closer to the nominal rate and smaller standard errors than several alternatives in small samples. Across seven empirical applications, we find that 2SDD has a smaller incidence of extreme _t_-statistics and outlying standard errors.