Thank you for your answer and sorry for being unclear. It is not that easy to describe. I will try to show you the data structure. The problem is that i need to calcuate a simple difference. Not a time difference but a difference of the value of a variable lets say at 2:15pm (now) and the value of the variable in 2:20pm which is also in the data set. So i have two data sets. Data set A contains the variable of interest called midquote and all limit orders that have been postet at a specific time. Data set B contains data about occuring trades (prices, quanitity) and a time variable. Data A (example, there are about 500 000 observations) midquote time 91.72 9:02:35.27 91.73 9:02:40.21 91.7 9:02:47.51 Data B tradepice time 91.73 9:02:36.27 91.6 9:02:40.21 91.74 9:02:41.21 What i need to do now is to subtract from the trade price now the value for the midquote that prevails 5 minutes later. The problem is that there is often no midquote exactly 5 minutes later which I need to take the closest one in time. There is the idea that for each trade i cut out a t+5 minute timeintervall of dataset A and take the last observation. However, i dont know exactly how to program such a loop. I hope I could give you some more information.
... View more