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

RE: st: probability mass function for a binomial distribution

From   Philip Ryan <>
Subject   RE: st: probability mass function for a binomial distribution
Date   Mon, 30 Jun 2008 11:21:25 +0930


I note [using Stata 10, latest] that -help Binomial- returns help on -binomial()- not on -binomialtail()-
I believe in other circumstances Stata returns an "out of date" message for functions and commands whose names have changed (e.g. -help index- )


At 03:07 AM 30/06/2008, you wrote:

Readers following along should note the renaming of various functions in
territory from Stata 9 to Stata 10. Stata 10 users can see -help

That is, Carlo, as he signalled, is using Stata 9.

Stata 9's -Binomial()- is Stata 10's -binomialtail()-.
-Binomial()- continues to work.

Thus I think this appearance of being undocumented  is in fact a
side-effect of name change.


Steven Samuels

I agree with Nick's advice to construct the functions on first
principles whenever possible.

Interestingly, Carlo has discovered the apparently undocumented
"survival' function  Binomial(k,n,p) equal to P(X>=k), whereas the
documented  function binomial(k,n,p) is P(X<=k).   Here is a version
of Carlo's  program with a correction for k= 20.


/*---------------------------begin example-------------------------*/
drop _all
set obs 21
g id=_n-1
g n=20
g k=_n-1
g p=.2
g  double  Binomial=Binomial( n, k, p)
g  double  PMF_Binomial=Binomial[_n]- Binomial[_n+1] in 1/20
replace    PMF_Binomial=Binomial[_n] in 21   //Correction

g double PMF2 = 0.2^k * 0.8^(20 - k) * comb(20, k)

list id n k p Binomial binomial PMF*
/*--------------------------end example----------------------------*/

On Jun 29, 2008, at 11:26 AM, Nick Cox wrote:

> 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
> 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:
Philip Ryan
Discipline of Public Health

Director, Data Management & Analysis Centre

Associate Dean (IT)
Faculty of Health Sciences

postal address:
Discipline of Public Health
Mail Drop 511
University of Adelaide 5005
South Australia

Level 6, Room 6-18
Bice Building
Royal Adelaide Hospital
North Terrace

tel +61 8 8303 3570
fax +61 8 8223 4075
CRICOS Provider Number 00123M
This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
copyright. If you are not the intended recipient please
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.

*   For searches and help try:

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