Dear All,

I want to run a generalized diff-in-diff regression that exploits time variation in state adoption of a policy to estimates the impact of the policy change on an outcome. Due to exogenous reasons there are significant state-specific time trends that vary over time in the outcome variables.The equation I want to estimate that allows for these state specific time trends is:
y_st = B x policy_st + X+ i.state + i.year + i.state#(c.year c.yearsq) error

Where X is a matrix of exogenous state level regressors. I have learnt that inclusion of state-specific linear and quadratic trends is problematic for 2 reasons - (1) overfitting and (2) in presence of dynamic treatment effects. An example of a study that discusses this is

https://www.nber.org/papers/w25018

Question 1

A proposed solution is to partial out the linear and quadratic trends using the Frisch-Waugh Lovell type projection matrices. But I am unsure how to proceed with this. Should I run
Step 1: Residualize i.state#c.year
reg policy_st i.state#c.year
predict resid_policy_st, res




Or should I also include X+ i.state + i.year here?

Then, how do I sequentially partial out
i.state#c.year #c.year ?



Question 2

I read that the command reghdfe actually does this exact thing. So I could run:

reghdfe y_st policy_st X i.state i.year, absorb(i.state#(c.year c.yearsq))

Is that correct?

I will be gateful for your input.
Sincerely,
Sumedha