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

st: RE: Re: Generating 'moving sum' variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: Generating 'moving sum' variable
Date   Wed, 3 Sep 2003 18:44:51 +0100

Michael Blasnik
 
> If there are no missing data, then a quick approach to get 
> a 7 period moving
> sum is:
> 
> bysort subject (day) : gen exer_cum=sum(exercise)
> by subject: gen exer_sum7=exer_cum-exercum[_n-6]
> 

This is a very cute method. It should give 
results equivalent to the time series methods
_unless_ there are gaps in the data, i.e. not
all dates are consecutive within panels. 

(I think this is what Michael means by his 
reference to missing data.) 

Nick 
n.j.cox@durham.ac.uk 

*
*   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–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index