Hello

This is not only a question about a code and you probably need to know the paper "A five-factor asset pricing model" but maybe somebody can help me anyway.

How did FF assign each stock to one of the 25 Size-BM, Size-OP & Size-Inv portfolio groups at the end of each June?

I already created the relevant variables (Book-to-market, operating profitability, investment, and additionally momentum).

Code:
** generate book-to-market ratio
generate bm = e/mv

** generate operating profitability
generate op = (s-cogs-i-sga)/e

** generate investment
by company: gen inv = (ta- ta[_n-12])/ta[_n-12]

** generate momentum
by company: gen mom = (mv[_n-1]/mv[_n-13])-1

** sort for 5 size and 5 B/M-, op-, inv-, & mom-groups
egen size_group = xtile(mv), by(date2) p(20 40 60 80)
egen bm_group = xtile(bm), by(date2) p(20 40 60 80)
egen op_group = xtile(op), by(date2) p(20 40 60 80)
egen inv_group = xtile(inv), by(date2) p(20 40 60 80)
egen mom_group = xtile(mom), by(date2) p(20 40 60 80)
My code assigns each stock at each month to one portfolio group. What I think I have to do, is evaluate at the end of each June if the portfolio group the stock is assigned to changes. But until then, the stock must remain in the assigned group.

I already tried something with this code to use the month.
Code:
gen month = month(date2)
If you have any idea how to solve the problem, I would really appreciate your help.

Thanks in advance!

Pascal