Hi,  
I have a dataset of couple of thousend stocks, which is attached to this question. I calculated the market capitalisation of each stock for a year. 
My goal know is to create 5 portfolios. Where every portfolio holds 20% of the stocks according to their size. The size is the market capitalisation. The portfolio should be recalculate every year. So the portfolio with the biggest 20 % of the stocks should incldude the biggest 20% for every year. 
Unfortunatly I' dont know how to do it. I was thinking about the splitapply() function. But i did not find a function for this. 
Data description:
ID is stands for the diffrent stocks 
years are the oberved years (1962-2016) 
sumMC is the market capitalization of each stock in every year
Does someone know how to do it? 
Thanks in advance