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

Re: st: product function

From (Roberto G. Gutierrez, StataCorp)
Subject   Re: st: product function
Date   Tue, 25 May 2004 12:00:43 -0500

Dimitriy V. Masterov <> asks:

> I would like to plot the probability that two people share a birthday as a
> function of the number of people in the room n. The formula is

> 	1-product((366-i)/365,i,1,n)

> In TeX, it would be

> 	1-\dprod\limits_{i=1}^{n}\frac{366-i}{365}.

> If I have a variable n={1,...,50}, how can I define the product within
> Stata? There does not seem to be math function that can do this.

The product is the exponentiated sum of the logs.

   . clear
   . set obs 100   // I assume that is enough, p(100) = .9999997
   . gen i = _n
   . gen p = 1-exp(sum(ln(366-i) - ln(365)))


P.S.  The break-even point on a bet is n = 23 people.

*   For searches and help try:

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