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.