Hi, Can someone help me to with the coding for the below,

I have a whole list of Company monthly market capitalization for 300 companies for 96 periods. For the same I have Monthly returns aswell.
I need to construct quintile portfolios based on market capitalization, where I get the monthly average return for each portfolio based on market cap.

Monthly returns for size portfolios.

Pls need help!!