Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Weekday data and tsset


From   Sergio Correia <sergio.correia@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Weekday data and tsset
Date   Mon, 15 Aug 2005 09:30:25 -0500

I think you have a few options available..

1) Generate a "trend" variable (1,2,3,4,5,6,7,8..) , so you can use a
generic time variable.

Then tsset it (tsset id generic_date) and when you want to do some
graphics or something like that, remember to use "date", not
"generic_date" to plot the axis).

2) Do a tsfill, full
Then, replace the missing values on the "price" variables with their
lag. (So the price on Sunday will be the same as the price on Friday.

You should take extra precaution in case there are some days in which
there are missing values in dates other than weekends.

Finally, every time you do a command, you should add " if dow(date)!=0
& dow(date)!=6 " to omit the weekends.

Btw, this are just hacks,  i don't think there is an elegant solution,
and I haven't tested this hacks, but I think they'll work.

Sergio


On 8/15/05, Daniel.Hoechle@unibas.ch <Daniel.Hoechle@unibas.ch> wrote:
> Dear all,
> 
> I have a panel dataset which contains daily stock prices of 80 different firms
> (variable: id). In order to calculate daily stock returns, it seems elegant to
> tsset (something like tsset id Date) the dataset and to use Stata's
> lag-operator (i.e. gen Return=Price/L.Price-1). However, as the dataset only
> contains weekdays, the panel has gaps and the stock return over weekends
> results to be missing when the lag-operator formula is applied. Of course, I
> could calculate the daily returns by typing
> 
> sort id Date
> by id (Date): gen double Return=Price[_n]/Price[_n-1]-1 if _n>1
> 
> But as calculating the returns like this is error prone in case of missing
> values, I wonder if either there is a special (time-series) date format for
> weekday data or if there is a simple way of transforming weekday data into
> "daily" data.
> 
> Thanks a lot for looking into this matter.
> 
> Kind regards,
> Daniel
> 
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> 
> *
> *   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