Hi, I'm new to Stata. Probably this question has already been answered, but I couldn't locate it.

I have a time series, 390 prices each day (1 min) of SPY (ETF). Dataset has the following columns:
1. date (same for each 390 minutes)
2. time (9:30 to 15:59) - 390 each date
3. spy (the closing minute price)
4. Also t, which is just observation number (gen t=_n)

I need to compute simple returns (d.spy/l.spy). I need to do it within each group (date), so that first minute return of the each day would be missing, because we can't compute it based on yesterday's closing price. I tried bysort date, but I'm doing something wrong, cos' it gives me the error 'not sorted':

. by date: generate spy_r = d.spy/l.spy
not sorted

. by date time: generate spy_r = d.spy/l.spy
not sorted

Thank you!
Yuri.