Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: generating cumulative sequence


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: generating cumulative sequence
Date   Wed, 21 Mar 2012 08:55:12 +0000

gen var2 = sum(var1)

General tip: Browse in the help for functions to see what you are
missing. If it's fundamental, it should be a function. If it's
important, but not fundamental, it may be an -egen- function.
StataCorp have absolute rights over defining what is fundamental.

For an eclectic, idiosyncratic, quirky and capricious highlighting of
some valuable functions, see

Cox, N.J. 2011. Speaking Stata: Fun and fluency with functions. Stata
Journal 11(3): 460-471.

Abstract.  Functions are the unsung heroes of Stata. This column is a
tour of functions that might easily be missed or underestimated, with
a potpourri of tips, tricks, and examples for a wide range of basic
problems.

Nick

On Wed, Mar 21, 2012 at 8:46 AM, Ivica Rubil <irubil@eizg.hr> wrote:

> How can I generate Var2 (see below), i.e. the cumulative sequence based
> on Var1? It seems an egen function can do the job, but which one? Or
> there's another solution? Thanks in advance.
>
> Var1               Var2
> -----------------------
> 1                    1
> 5      1+5 =         6
> 6      1+5+6 =      12
> 8      1+5+6+8 =    20
> 12     1+5+6+8+12 = 32

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index