[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Tsset question: calculating returns using daily prices - weekend issue
This is precisely the issue dealt with in Stata Tip 40:
Essentially you establish two calendar variables for the data: the
second a sequential integer based on trading days. Sort the data
based on a dummy (price < .) and your existing date variable, which
will percolate the missings to the end, and generate t = _n if price
< . -- if you then tsset t, you are looking at the data in 'market
time'. You can always return the data to calendar time with tsset
date. This trick was discussed by David Drukker at NASUG'2006 in Boston.
If the Stata Journal is not in your university library, bug the
library about it, or subscribe yourself! Well worth it.
Kit Baum, Boston College Economics and DIW Berlin
An Introduction to Modern Econometrics Using Stata:
On May 8, 2007, at 2:33 AM, Nuno wrote:
I have a sample that is composed of daily (date) share prices (prc)
set of companies identified by id. I wanted to calculate the daily
for each share. In order to do this I used the tsset command:
tsset id date, daily
However, given that stocks are not traded during the weekend, the gen
command generates a missing value every Monday (in the example I
gap for share 1 from 10-Jan to 20-jan generates a missing return).
a way of avoiding this problem, ie, that the l. operator gets the
time observation even if it isn't the one from the previous day?
I know that I can solve this problem by doing:
sort id date
by id: gen ret=prc/prc[_n-1]-1
But I would like to know if this can also be achieved using the l.
* For searches and help try: