Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Tsset question: calculating returns using daily prices - weekend issue

From   "Nuno" <>
To   <>
Subject   st: RE: Tsset question: calculating returns using daily prices - weekend issue
Date   Tue, 8 May 2007 13:52:21 +0100

Thanks for the tips Kit and Daniel! 

-----Original Message-----
[] On Behalf Of Kit Baum
Sent: terça-feira, 8 de Maio de 2007 11:48
Subject: st: Tsset question: calculating returns using daily prices -
weekend issue

sacrificial goat

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) 
> for a set of companies identified by id. I wanted to calculate the 
> daily return for each share. In order to do this I used the tsset 
> command:
> tsset id date, daily
> gen ret=prc/l.prc-1
> However, given that stocks are not traded during the weekend, the gen 
> command generates a missing value every Monday (in the example I 
> attach the gap for share 1 from 10-Jan to 20-jan generates a missing 
> return).
> Is there
> a way of avoiding this problem, ie, that the l. operator gets the 
> previous 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.  
> operator.

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index