Dear Stata community,

I'd like to generate a variable that records the number of unique values of a variable (var1) within each value of another variable (var2) over a rolling time window defined by a date variable.I cannot really come up with codes that could provide the results I'm looking for. I wondered if anyone could provide some thoughts? Any help would be greatly appreciated.