If you want to create two groups of firms in each year, then something like the following will work:
* For creating two groups of firms in each year, I am using astile. More on astile here
ssc install astile, replace
*Download example data
webuse grunfeld, clear
*Create two groups based on mvalue
bys year: astile size = mvalue, nq(2)
*Cross-sectional regression
*For Cross-sectional regression, install asreg, more on asreg here
ssc install asreg, replace
*Yearly cross-sectional regression for each size group
bys size year: asreg invest mvalue kstock