Dear community,

I have a dataset with about 3 million observations. Each observation has a time id, at which it was observed, and a position.

The variables have these formats:
time_id = {1, 2, 3, ... , 286, 287, 288}. Each id covers a time slot of 5 min, so 12 ids are 60 min.
position = {1, 2, 3, ... , 19, 20, 21}

I want to create a variable that gives me the highest position value of all observations in the past hour for each observation.

So basically, the command I wanna use is: "for observations betwenn time_id and time_id - 12": egen lowestposition = max(position).

For example if the observation has the time_id 250, I would like to get the highest position value of all observation with time_id 238, 239, 240, ... 249, 250. Then for an observation with time_id 251, I would like to get the highest position value of all observation with time_id 239, 240, 241, ... 250, 251.

Can you help me with finding a command for that?


Thank you so much!
Carina