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

st: Re: Generating 'moving sum' variable


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Generating 'moving sum' variable
Date   Wed, 3 Sep 2003 11:27:18 -0400

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]

Michael Blasnik
[email protected]

----- Original Message ----- 
From: "KRISTIEN VERHEYEN" <[email protected]>
To: <[email protected]>
Sent: Wednesday, September 03, 2003 7:39 AM
Subject: st: Generating 'moving sum' variable


> hello,
>
> I have a survival-time dataset with daily observations per subject. One of
> the (numeric) variables represents daily exercise distance. I now want to
> create a new variable that represents the sum of exercise distance in the
> previous week (or 7 days). It sounds similar to the 'moving average'
option
> for egen but there doesn't seem to be a 'moving sum' option. Please can
> somebody help? Thank you very much.
>
> Kristien Verheyen
> PhD student
>
> **********************************************
> Visit our website at www.aht.org.uk
> **********************************************
>
>
############################################################################
#########
> This e-mail message has been scanned for Viruses and Content and cleared
> by MailMarshal
> For more information please visit www.marshalsoftware.com
>
############################################################################
#########
> *
> *   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/
>


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