Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: How to aggregate daily data in Stata


From   "Christopher A. Hartwell" <christopher.hartwell@msn.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: How to aggregate daily data in Stata
Date   Sun, 16 Dec 2012 00:46:23 +0400

Hi all,

Have a question that should be easy to figure out for the experts, but I
can't wrap my mind around it conceptually. 

I have daily stock market data for 28 countries over a 20-odd year period.
Some countries have 6 years of data, some have 20 years, etc., depending on
when they started their stock markets. I want to calculate a volatility
metric by using the sum of squares of daily changes for each month (that is,
aggregate the daily squared changes for each month). Given that the panel
data has different time lengths and there are different monthly periods
(i.e. some months have 30 days, some countries have holidays in the month so
there's no data), how can I use stata to sum the squares of the daily
changes by month? 

For example, I have

Belarus		March-1-05	1.37
Belarus		March-2-05	0.69
.
.
.
Belarus		March 31-05	17.33

And I want to generate one variable per country per month that is the sum of
these numbers, so that I have

Belarus		Mar-05		37.20
Belarus		Apr-05		18.99

Etc.

Is there an easy "by x:" command that will let me do it? Or some iteration
that will allow for this?

The problem I see is that I need to sum the data first by day over a
specific month, for each month, for each country, on a dataset that is
severely unbalanced. It seems like there might be too much going on here for
stata to handle. Is this the case?

Thanks,

Christopher A. Hartwell, PhD
Senior Research Fellow
Institute for Emerging Market Studies (IEMS)
http://iems.skolkovo.ru/ 

In Moscow: +7 916 777 1260 (m)
In the US:    +1 202-415-6030 (m)
                        +1 773-724-2310 (t/f)
Skype: chartwel
Christopher.hartwell@msn.com 



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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