Hello,

I am very new to Stata, so please excuse my inexperience.

I am using a data set comprised by the variables future, enddate, date, price, tk, S1_1, S1_1_TK, SKX.
"Future" refers to the settlement period of the future, enddate specifies the date of settlement, date is connected to price and specifies the date in which the price can be observed, tk is a constant 100bp for transaction costs, S1_1 refers to the spread in effect at the specified date between the future and the previous future, S1_1_TK is the spread minus the transaction costs at the time of opening the position and SKX refers to the settlement price of the future.

Now I would like to generate a new variable "S1_1_TK2". S1_1_TK2 should be comprised of S1_1_TK and the transaction costs at the time of closing the position. Thus I need to refer to the settlement price of the prior period future.

In this case (and as you can see in the screenshot attached) I want to refer to SKX=6,98 when calculating the value of S1_1_TK2 for the Dec-12 future.

I tried:

gen S1_1_TK2 = S1_1_TK - SKX[_n-1] * tk

Obviously this does not work expect for the first Dec-12 future. For all the following Dec-12 future this command refers to the closing price of the Dec-12 future aswell.

So I would need to find an command which refers to the first observation of the variable SKX which differs from the current observation.


Thanks!
Array