Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Re: Cumulative sum


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Re: Cumulative sum
Date   Mon, 3 May 2004 20:21:16 +0100

Michael is correct. Your guess is not! 

Perhaps you are confusing the function -sum()-
with the -egen- function -sum()-. 

Nick
[email protected] 

de la Garza, Adrian
 
> I don't think that gives me the cumulative sum, does it? It 
> gives me the
> overall sum by country. That is, for every observation for which the
> country is the same, I will get the same 'sum' variable, if I 
> do it that
> way...
 
Michael Blasnik 

> > no loop needed...
> > 
> > by country: gen cum_amount=sum(amount)

de la Garza, Adrian
 
> > > I would like to create a variable that gives me the 
> cumulative of an
> > > amount by country, like so:
> > > 
> > > country year quar amount cum_amount
> > > Argentina 1990 1 100 100
> > > Argentina 1990 2 50 150
> > > Argentina 1990 2 25 175
> > > Argentina 1990 2 100 275
> > > Argentina 1990 3 200 475
> > > ...
> > > Bolivia 1990 1 25 25
> > > Bolivia 1990 1 30 55
> > > ...
> > > 
> > > Does anyone know a command that would do this without 
> > needing to write a
> > > loop?

*
*   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