# st: RE: RE: RE: product function

 From "Nick Cox" To Subject st: RE: RE: RE: product function Date Tue, 25 May 2004 18:55:12 +0100

```I don't think it is explicit anywhere in the manual, but
you can assume that -generate- and -replace- follow the
current sort order of the observations.

. generate y = sum(x)

and

. replace z = z[_n-1] if mi(z)

would not work as you expect otherwise.

http://www.stata.com/support/faqs/data/missing.html

That said, exp(sum(log()) is perhaps preferable
for cumulative products. Naturally there is a
different behaviour whenever 0 is one term in the
product.

Phil Ryan has written various -egen- functions
in this territory.

Nick
n.j.cox@durham.ac.uk

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Roger Newson
> Sent: 25 May 2004 18:44
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: RE: product function
>
>
> At 18:00 25/05/04 +0100, Nick Cox wrote:
> >Woops. Sorry, Professor Feller!
> >
> >. set obs 50
> >. gen i = _n
> >. gen double p = 1 - 1/365
> >. replace p = p[_n - 1] * (1 - _n / 365) in 2/l
> >. replace p = 1 - p
> >. scatter p i
>
> Thanks for that trick, Nick. I wasn't aware that you could do
> recurrence
> relations in Stata that way. I always somehow assumed that
> the -replace-
> command in Stata created a whole new variable as a result,
> assigned its
> values on the basis of pre-existing variables, and then
> variable and put the new one in its place. Evidently, it
> doesn't do that,
> and instead writes directly to the old variable, observation by
> observation, using the previous observation(s) as input if
> This trick will no doubt be useful next time I need to do a
> recurrence
> relation. I have noted, of course, that the last character in
> the 4th line
> is a l (the lower case version of L), and not a 1 (the digit one).
>
> Roger
>
>
> --
> Roger Newson
> Lecturer in Medical Statistics
> Department of Public Health Sciences
> King's College London
> 5th Floor, Capital House
> 42 Weston Street
> London SE1 3QD
> United Kingdom
>
> Tel: 020 7848 6648 International +44 20 7848 6648
> Fax: 020 7848 6620 International +44 20 7848 6620
>    or 020 7848 6605 International +44 20 7848 6605
> Email: roger.newson@kcl.ac.uk
> Website: http://www.kcl-phs.org.uk/rogernewson
>
> Opinions expressed are those of the author, not the institution.
>
> *
> *   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/
```