Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Stopping and Starting a Running Sum


From   Martin Weiss <martin.weiss@uni-tuebingen.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Stopping and Starting a Running Sum
Date   Tue, 24 Jun 2008 21:30:04 +0200

Version 1.0:

*******
g SumHours=Hours
bys ID: replace SumHours=cond(Date[_n]-Date[_n-1]<2, SumHours[_n-1]+Hours[_n], Hours[_n])
*******





Zitat von jasonm@ucla.edu:


I would like to create a running sum (eg SumHours) that restarts
whenever there is a change in ID or the difference between the current
date and previous day's date is >1.

ID  Hours    Date   SumHours
1    2      16437     2
1    3      16438     5
1    2      16440     2
1    2      16441     4
2    4      16437     4
2    3      16440     3
2    4      16441     7
2    2      16442     9
2    2      16443     11

Any ideas?

Thank  you.

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