Dear Stata community,

I have stock returns file from CRSP where the date format follows business calendar (for e.g. 12Apr2019). For each stock (id), I want to compute the number of trading days, over non-missing observations, in last three years. Since number of trading days might differ over years, and also for different stocks, when new firms enter and/or some existing firms drop, the computations will differ for each id over the same period. Thus, I want to specify a 3-year range for each id over the trading days during the last three years (13Apr2016 to 12Apr2019).

I am not sure how to specify the rolling window for each id’s non-missing obs in the interval part of rangestat syntax:
rangestat (count) price, interval(date -xx 0) by(id)

I have been trying to find some guidance available online but I have not been able to find clear guidance since most intervals are illustrated within a few trading days, such as 3, 5, and 90) window.

Any guidance will be sincerely appreciated!

Thanks for reading.

Kind regards,
Manish