Statalist


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

RE: st: RE: Adding cumulatively


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Adding cumulatively
Date   Thu, 15 May 2008 18:56:45 +0200

You might have mistaken -sum()- for -egen, total- then...

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:46 PM
To: [email protected]
Subject: Re: st: RE: Adding cumulatively

Thanks. For some reason I though sum function will produce the same
total sum against all values.

Thanks again.



On Thu, May 15, 2008 at 11:42 AM, Nick Cox <[email protected]> wrote:
> 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/
>
*
*   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