--- Zachary Harrison wrote:
> I have a monthly time series with say 30 months and
> 50-100 countries per month. I have GDP for each
> observation.
>
> For a window of 24 months, I wish to calculate the
> standard deviation of all observations within the
> window. So in month 24 I want my variable to be the
> standard deviation of the GDPs of all countries from
> months 1-24. In month 25 I want the stdev of GDP for
> all countries from months 2-25, etc.
You can build a loop, like in the example below:
*---------- begin example ---------------
use "http://home.fsw.vu.nl/m.buis/stata/pwt.dta"
sum year
local start = r(min) + 1 /* window = 2 years */
local end = r(max)
forvalues y = `start'/`end' {
local initial = `y' - 1
/* `initial' = start window */
/* `y' = end window */
qui sum cgdp if year >= `initial' & year <= `y'
di `initial' " - " `y' ": " r(sd)
}
*-------------- end example -------------
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
*
* 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/