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

RE: st: probability mass function for a binomial distribution

From   "Nick Cox" <>
To   <>
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. 


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
of an in-built for calculating the (probably too trivial) probability
function for a binomial distribution, which is instead available within
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
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:

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