|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Adding cumulatively
**********
sort id
by id:g cumvar1=sum(var1)
**********
possibly combined with a foreach loop...
Martin Weiss
_________________________________________________________________
Diplom-Kaufmann Martin Weiss
Mohlstrasse 36
Room 415
72074 Tuebingen
Germany
Fon: 0049-7071-2978184
Home: http://www.wiwi.uni-tuebingen.de/cms/index.php?id=1130
Publications: http://www.wiwi.uni-tuebingen.de/cms/index.php?id=1131
SSRN: http://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=669945
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Rijo John
Sent: Thursday, May 15, 2008 6:24 PM
To: stata
Subject: st: Adding cumulatively
Hi 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.
Thanks.
*
* 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/