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" <liststata@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
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-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Kit Baum
Sent: terça-feira, 8 de Maio de 2007 11:48
To: statalist@hsphsun2.harvard.edu
Subject: st: Tsset question: calculating returns using daily prices -
weekend issue

sacrificial goat

This is precisely the issue dealt with in Stata Tip 40:
http://ideas.repec.org/a/tsj/stataj/v7y2007i1p137-139.html

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

Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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