Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: Lagged price

From   "Brad Wright" <[email protected]>
To   <[email protected]>
Subject   st: Re: Lagged price
Date   Fri, 28 Jan 2011 17:21:16 -0500

I don't know of a formula per se, but you should definitely take advantage of Stata's time-series operators for lagging variables.

You must first use tsset or xtset to tell Stata what format your data are in, and then creating lags is very simply done by using "L.varname" for 1 lag or "2L.varname" for 2 periods and so on.

Then you can write a piece of code that will automate this for you so that you can loop through all the combinations, stopping when you find the first "non-matching" period.


↑ Grab this Headline Animator
----- Original Message ----- From: "Beatrice Crozza" <[email protected]>
To: "statalist" <[email protected]>
Sent: Friday, January 28, 2011 5:08 PM
Subject: st: Lagged price

Dear All,

I want to infer the trade direction with a tick test, comparing two
consecutive prices.
I have a problem with Stata in order to construct the lagged price.
When two consecutive prices are the same, I should go back one more
lag, however, often I need to compare my price with a price of three
or more previous periods.

Here there is an example of my dataset:

date          time         price
03jan2000 93157 148.25
03jan2000 93200 148.25
03jan2000 93201 148.27
03jan2000 93202 148.25
03jan2000 93203 148.25
03jan2000 93208 148.25
03jan2000 93211 148.25
03jan2000 93212 148.25
03jan2000 93215 148.15625
03jan2000 93225 148.25

if I compare price at 93212 with the previous one, it is the same and
also if I compare it with the price at 93208, so I should go further
until I reach the price of 93201 which is different.

If I want to do the difference for two consecutive prices I can write:
a lag further:
and so on

However, I would like to know if there is a formula to do the
difference between to prices, until I find a price which is different
from the one in consideration.

Thank you very much or your help.

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index