```help mata mm_cebinomial()
-------------------------------------------------------------------------------

Title

mm_cebinomial() -- Conditional expectation of a binomial distributed
random variable

Syntax

real matrix mm_cebinomial(n, k, p)

where

n:  real matrix n
k:  real matrix k
p:  real matrix p

Description

mm_cebinomial() returns the expected value of a binomial distributed
random variable conditional on the variable being equal to k or larger.
That is, mm_cebinomial() returns

E(X|X>=k)

where

X ~ B(n, p)

and n is the number of trials and p is the success probability.

When n, k, and p are not scalar, mm_cebinomial() returns
element-by-element results. n, k, and p are required to be r-conformable
(see help [M-6] glossary).

Remarks

The expectation of X ~ B(n, p) conditional on X>=k may be written as

E(X|X>=k) = k + [ P(X>=k+1) + ... + P(X=n) ] / P(X>=k)

where P(X>=k) is the probability of k or more successes, which is
computed as Binomial(n, k, p) (see [M-5] normal()).

Conformability

mm_cebinomial(n,k,p) requires n, k, and p be r-conformable (see help
[M-6] glossary). Returned is a matrix of max(argument rows) rows and
max(argument columns) columns containing element-by-element calculated
results.

Diagnostics

mm_cebinomial() returns missing if any of the arguments are missing.

mm_cebinomial() returns missing if arguments are out of range (p>1, p<0,
n<=0, k<0, or k>n) or if n or k are non-integer.

Source code

mm_cebinomial.mata

Author

Ben Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also see

```