The original example was a little special
in that a variable -ob- already exists
with exactly the desired properties.
A detail worth pointing out briefly is
that the solutions so far all
assume that -calc- is never missing.
More general code would be
bysort pid (ob) : gen cave = sum(calc) / sum(calc < .)
Nick
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of
> Daniel Lawson
> Sent: 06 October 2004 21:39
> To: [email protected]
> Subject: Re: st: cumulative average moving through time
>
>
> The command-line ``bysort pid (ob):gen cave = sum(calc)/ob'' was
> exactly the sort of thing I had in mind when I said that I was sure
> there was a more elegant way to produce the results. I ran both sets
> of code, and both produce the same values for `cave'.
>
> Daniel Lawson
>
> On Oct 6, 2004, at 2:59 PM, Daniel Egan wrote:
>
> > Oh, and thanks. I did not get to try Dan Lawson's code.
>
> *
> * 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/