[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

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

Subject |
RE: st: probability mass function for a binomial distribution |

Date |
Sun, 29 Jun 2008 16:26:30 +0100 |

What is available as a defined function shows up a trade-off problem. It wouldn't be difficult to define a thousand functions, but then some people might complain about the complexity of the list and the difficulty of finding a solution. Otherwise put, I guess the answer to Carlo's question is that Stata users -- unlike spreadsheet users, it seems --- are paid the compliment of knowing enough statistics to work this out from first principles: gen double bmp = p^k * (1 - p)^(20 - k) * comb(20, k) Note in passing two other details: I prefer to use -double-s here. Putting constants into variables isn't necessary: gen double bmp = 0.2^k * 0.8^(20 - k) * comb(20, k) In cases like this the advantage of a canned function over a one-line solution using another canned function would be pretty small. Nick n.j.cox@durham.ac.uk Carlo Lazzaro I have probably found out the answer to my last Friday thread. I do hope this may be useful for someone else on the list. However, a little concern remains about the lack among Stata 9.2/SE commands of an in-built for calculating the (probably too trivial) probability mass function for a binomial distribution, which is instead available within the most widespread spreadsheets. One more time, my grateful thought go out to Steve and Nick (in order of appearance in my incoming e-mail folder) for pointing me out the importance of a step-by-step research in dealing with Stata troubles. ---------------------------begin example------------------------- set obs 21 g id=_n-1 g n=20 g k=_n-1 g p=.2 g Binomial=Binomial( n, k, p) g PMF_Binomial=1- Binomial if id==20 replace PMF_Binomial=Binomial[_n]- Binomial[_n+1] in 1/20 --------------------------end example---------------------------- * * 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/

**Follow-Ups**:**R: st: probability mass function for a binomial distribution***From:*"Carlo Lazzaro" <carlo.lazzaro@tin.it>

**Re: st: probability mass function for a binomial distribution -correction***From:*Steven Samuels <sjhsamuels@earthlink.net>

**Re: st: probability mass function for a binomial distribution***From:*Steven Samuels <sjhsamuels@earthlink.net>

**References**:**R: st: probability mass function for a binomial distribution***From:*"Carlo Lazzaro" <carlo.lazzaro@tin.it>

- Prev by Date:
**RE: st: how to retain a complicated subset of data** - Next by Date:
**Re: st: probability mass function for a binomial distribution** - Previous by thread:
**R: st: probability mass function for a binomial distribution** - Next by thread:
**Re: st: probability mass function for a binomial distribution** - Index(es):

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