| ![]() |
From | Kit Baum <baum@bc.edu> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Tsset question: calculating returns using daily prices - weekend issue |
Date | Tue, 8 May 2007 06:47:49 -0400 |
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/
© Copyright 1996–2025 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |