[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Brian P. Poi" <bpoi@stata.com> |

To |
statalist <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: probability question |

Date |
Wed, 28 Oct 2009 09:03:47 -0500 (CDT) |

On Wed, 28 Oct 2009, Richard Goldstein wrote:

during a consecutive period of 120 days, if it rains on 7 days and my client wears a hat on 4 days (these are independent of any knowledge of the weather), what is the probability that it will rain on 3 of the days on which he is wearing a hat?

---------------------------------------- mata: rseed(1) tries = 10000000 totaln = 0 for(i=1; i<=tries; ++i) { // rain has 7 ones rain = J(120, 1, 0) rain[1..7] = J(7,1,1) // hat has 4 ones hat = J(120, 1, 0) hat[1..4] = J(4,1,1) // shuffle each one _jumble(rain) _jumble(hat) // if there's a match, hat+rain==2 both = rain + hat matches = sum(both:==2) // we want to know if there were three matches if (matches == 3) { totaln = totaln + 1 } if (mod(i, 1000) == 0) { printf(".") } } printf("\n\nProbability is about %10.8f\n", totaln/tries) end ---------------------------------------- -- Brian Poi -- bpoi@stata.com * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: probability question***From:*Richard Goldstein <richgold@ix.netcom.com>

**References**:**st: probability question***From:*Richard Goldstein <richgold@ix.netcom.com>

- Prev by Date:
**RE: st: probability question** - Next by Date:
**Re: st: xtmelogit with variable as fixed and random effect error r(3200)** - Previous by thread:
**Re: st: RE: RE: probability question** - Next by thread:
**Re: st: probability question** - Index(es):

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