I have an unbalanced panel dataset, potentially with gaps. Time is coded as daily, but is really monthly (there is always just the first day of each month).

Here is an MWE with two units (id) over time periods (t) and the variable of interest (x)

Code:
input id str16 t x
1    "01jan2002" 1
1   "01feb2002" 1
1   "01mar2002" 0
1   "01aug2002" 1
2    "01jan2002" 1
2   "01feb2002" 1
2   "01may2002" 0
2   "01jun2002" 1
end
I want to create the cumulative rolling window sum of x starting at period t and then moving a fixed number of months forward. Let's say 3 months here. The issue is that I may have gaps and I think it would be better to identify the end based on the date variable rather than using the _n+3 observation.

Somebody has an idea how to tackle this?