Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: How to aggregate daily data in Stata

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: How to aggregate daily data in Stata Date Sat, 15 Dec 2012 22:14:48 +0000

```. help collapse

Nick

```
On 15 Dec 2012, at 20:46, "Christopher A. Hartwell" <christopher.hartwell@msn.com > wrote:
```
```
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.
```
```*
*   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/
```