Hellow everyone,I wanna to divide stock monthly return into three groups based on the original return of 11 months dating from the end of monthly t − 2,how can I do it.

I only did the end of monthly t-2 by use "gen portfolioday=cond((date==lastdate)&(month[_n-2]),1,0)"

How to achieve grouping in the following time period?

THX