Diff-in-Diff estimation in R where all IDs are treated but at different points in time I asked this question on stack overflow and was advised to post it here instead.  I am trying to run a diff-in-diff on a dataset at the person-day level, where all individuals in the dataset are treated, albeit at different points in time. There are 5 treatment dates, so, for instance, person X receives the treatment on day 1, person Y receives the treatment on day 10, person Z on day 5, and so forth. What's important here is that every person is treated eventually. Here's a stylized visual representation of the data (where LHS is the dependent variable):

Now, what I am trying to do is run a diff-in-diff where I compare person Z that was treated on day 5 with person Y that was not yet treated on day 5 (so, in this setup, person Y would serve as the control group).  This criteria would have to be extended to all the individuals in the sample so as to run a diff-in-diff simultaneously for all people.
I am not sure how to code this up in R.  I am pretty familiar with the feols function in R as I have used it several times in the past to run conventional diff-in-diffs such as the one illustrated here: https://lost-stats.github.io/Model_Estimation/Research_Design/event_study.html.  However, in this particular case, I am not sure what I should be interacting Days_To_Treatment with since if I interact it with Treatment every observation prior to Days_To_Treatment = 0 will be dropped.
I am honestly pretty clueless as to how to approach this at the moment.  Any help, advice, or tip would be greatly appreciated.
Thanks
 A: Your question is principally concerned with the "interaction term" in a difference-in-differences model with a staggered treatment. In practice, a product term will not return the treatment effect you're looking for, in part because the post-periods vary across persons. There's no well-defined post-treatment phase to assign to your controls, assuming you even have a subset of persons never experiencing a treatment. In short, you do not need to interact anything, just include that treatment variable—as is.
For example, say you just want a single summary measure of the treatment effect. Well, the column labeled "Treatment" is exactly what you need in this setting. It's 'turning on' (i.e., switching from 0 to 1) in precisely those person-day combinations where the treatment is in effect, 0 otherwise. In other words, the variable equals 1 if a person is in the treatment group and is in a post-treatment period, 0 otherwise. This is typically how we define a treatment/policy variable in a setting where there is a staggered/non-uniform exposure pattern. Just note that your estimate is restricted entirely to variation in the "timing" of your treatment.
In terms of obtaining estimates for the relative days around the first day of exposure, it's just a little extra pre-processing before we run the model. The column labeled "Days_To_Treatment" is the exactly what you need, assuming it's coded properly. Each person in the sample is some amount of days approaching (moving away from) that first day of exposure, which we often define as time period 0. I go over the creation of the relative treatment/policy variable in detail here. Once you see how it's coded in practice, you start to understand how it's actually an "interaction term" just defined in a different way.
In software, I recommend defining the relative treatment measure as a factor variable, but you don't have to do this. The feols() function is smart enough to do this for you. In particular, the i() syntax will coerce "Days_To_Treatment" into a factor variable and 'dummy out' those relative period effects. Further, i() also has the added benefit of allowing the user to define the reference period. The boilerplate R code below should be adapted to your specific use case, but it seems like everything should work just fine if the data frame is organized as it is in your post.
# A 'fixest' solution
# Estimate the relative period effects
# The function i() allows the user to define which period to omit

# library(fixest)

est_rel_periods <- feols(y ~ i(days_to_treatment, ref = ...) | person + day, data = ...)

# Plot the coefficients

iplot(est_rel_periods)

In the comments, you referenced a previous answer of mine, which departs from your setting in a fundamental way. In that response, I recommend code showing the interaction of a treatment/control dummy with a post-treatment indicator for the periods "after" treatment. Note the major difference: treated units in that sample started treatment at the same time. We then assume the control group would have started treatment around the same time. Unless you use some sort of matching framework to group treated/untreated individuals, you cannot claim any one particular person would have entered into treatment on the same day as another person. I suppose if the treatment had some sort of standardization in its roll out, we could perhaps infer a reasonable start date for the controls. But, even this suggestion is moot, because the treatment affects everyone, eventually.
As a last word, I cannot tell you which period to omit; that is for you to decide. All I can say is the most popular choice in the literature I've surveyed is the period (day) immediately before the first day of treatment (i.e., -1). A more distant pre-period is not uncommon, but just be prepared to offer a quick explanation as to why you chose that period. Again, this is a soft recommendation. Please be guided by others with experience in your particular discipline.
