[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Adding cumulatively
From
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
st: RE: Adding cumulatively
Date
Thu, 15 May 2008 17:42:09 +0100
bysort id (year) : gen cumvar1 = sum(var1)
Skim through the help on functions for problems like these.
Nick
[email protected]
Rijo John
I have a data as follows.
Year ID var1 var2
1 1 4 6
2 1 5 8
3 1 2 2
4 1 3 7
1 2 5 1
2 2 7 5
3 2 6 4
4 2 4 9
I need cumulative sums of var1 and var2 by ID
so that it will become
Year ID var1 var2 cumvar1 cumvar2
1 1 4 6 4 6
2 1 5 8 9 14
3 1 2 2 11 16
4 1 3 7 14 23
1 2 5 1 5 1
2 2 7 5 12 6
3 2 6 4 18 10
4 2 4 9 22 14
I have more than two vars. Can some one please help.
*
* 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 |