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" <>
To   <>
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.) 


*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index