Statalist The Stata Listserver


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

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


From   "Nuno" <liststata@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Tsset question: calculating returns using daily prices - weekend issue
Date   Mon, 7 May 2007 21:56:49 +0100

Hi everyone,

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.

All the best,

Nuno

id	date		prc		ret
1	01jan2000	.8814709	
1	02jan2000	.3900488	-.5575023
1	03jan2000	.0795536	-.7960419
1	04jan2000	.5782917	6.269206
1	05jan2000	.8495564	.4690796
1	06jan2000	.9873733	.1622221
1	07jan2000	.5633137	-.4294826
1	08jan2000	.9146034	.6236131
1	09jan2000	.9343885	.0216324
1	10jan2000	.4494989	-.5189379
1	20jan2000	.6151019	
1	21jan2000	.278718	-.546875
1	22jan2000	.7391275	1.651883
1	23jan2000	.5166555	-.3009927
2	01jan2000	.2482313	
2	02jan2000	.2797685	.1270476
2	03jan2000	.4782088	.7093018
2	04jan2000	.5516245	.1535221
2	05jan2000	.4525468	-.1796107
2	06jan2000	.8578724	.8956543

*
*   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