Statalist


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

st: running sum restarting after missing value


From   "Erasmo Giambona" <[email protected]>
To   statalist <[email protected]>
Subject   st: running sum restarting after missing value
Date   Fri, 20 Jul 2007 13:23:55 +0200

Dear Statlist,

I am trying to create a running sum using the sum function by group.
My problem is that I would like STATA to restart summing again after
each missing value and match the total with all previous observations.
For example:

id yeara var1
1 1984 1
1 1985 1
1 1986 1
1 1987 .
1 1988 1
1 1989 1

My output should look like

id year var1 sum_var1
1 1984 1 3
1 1985 1 3
1 1986 1 3
1 1987 . .
1 1988 1 2
1 1989 1 2

I tried the following, but it doesn't get me what I need.

by id: gen sum_var1=sum(var1) if var1!=.

Any suggestions on how I could get my result would be appreciated.
Regards,
Erasmo
*
*   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