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

Re: st: cumulative average moving through time

From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   Re: st: cumulative average moving through time
Date   Wed, 6 Oct 2004 16:31:55 -0400

see -help functions- for the very long list of available functions.  The sum
function calculates a cumulative sum for each observation, within each by
group (the by varlist Not in parentheses).  For egen, sum calculates a
constant within by group equal to the sum for that entire group.

Michael Blasnik
[email protected]

----- Original Message ----- 
From: "Daniel Egan" <[email protected]>
To: <[email protected]>
Sent: Wednesday, October 06, 2004 3:59 PM
Subject: Re: st: cumulative average moving through time

> Hi Scott,
> by sort pid (ob):gen cave = sum(calc)/ob
> This is so obvious as to be painful. So why didn't I think of it?
> 1) Where/When did -sum()- become an acceptable argument to
> -generate-!?!? I have only ever seen it in the context of -egen-.
> Looking at the help for -generate-, there are no arguments that are
> explicitly stated to be useable. It is only at the very bottom of the
> examples that one sees an function -uniform-  and then -sum- used with
> gen. Are the others?  I know that using many egen arguments with -gen-
> will return errors (e.g. count).
> 2) Why does the ---bys pid (ob)-- do this correctly? I understand that
> it is equivalet to --sort PID OB--, but why does it result in the
> correct cumulative sum?
> Another way of putting this is why doesnt -egen cave=sum(calc)/ob,
> by(PID OB)- work if this does?
> Sorry if this is a lot, I am just surprised about this.
> Oh, and thanks. I did not get to try Dan Lawson's code.
> Dan Egan

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index