Dear Statalist members,

I am new to Stata and would appreciate any help/insights you could give me, in dealing with the following.

I am working with a panel data of stocks, their time series of monthly returns and other fundamental data. I am trying to do the following:
1. Rank stocks on specific dates t (June each year) based on the realization of one of the fundmental variables x
2. Allocate the stocks to portfolios (i.e. 30% highest realizations in the high_portfolio and 30% lowest realizations in the low_portfolio)
2. Calculate portfolio returns from t+1 to t+12 (i.e. how does the high_portfolio perform subsequent to formation and how does this compare to the low_portfolio?)

I have had a look at some previous similar threads but I have not been able to piece everything together.

For step 1, I am trying to create a local list of all the June observations per year so that I can refer to them in ranking the portfolios.However, I am getting the error message _( invalid name
r(198);
Code:
local(formationt) if month=(06)
For step 3, I am struggling to figure out how to tell Stata to focus only on the stocks belonging to a certain percentile group as identified in step 2 and use their individual return series to compute a portfolio return series for the next year.

Thank you in advance for any help!

Nour