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

Re: st: product function


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

Dimitriy V. Masterov <[email protected]> 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)))

--Bobby

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

--Bobby
[email protected]
*
*   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