Inna Becher <[email protected]> wrote,
> I would like to implement a comb(n,k) function. But my Stata does not
> allow it because of large n, k-numbers. N=180000 and k=2000. Is there
> any other way to do it? I wasn't successful by using exp(lnfactorial(n))
> in mata as well.
Maarten buis <[email protected]> replied,
> The outcome of comb(180000,2000) is going to be,
> ridiculously large (> 8e+307) and it hits the limit of what
> can be stored in double precision [...]
Yes, that's right. In fact, the answer is between 1e+4770 and 1e+4771.
comb(n, k) is defined
n!
comb(n, k) = --------- = (n!)/( k! (n-k)! )
k! (n-k)!
Thus,
ln(comb(n,k) = ln( (n!)/( k! (n-k)! ) )
= ln(n!) - ln(k!) - ln(n-k)!
Stata has a lnfactorial() function, so we can plug in and get
. scalar n = 180000
. scalar k = 2000
. display lnfactorial(n) - lnfactorial(k) - lnfactorial(n-k)
10983.753
In log base 10, that 10983.753/ln(10) = 4770.1833. Hence my statement,
the answer is between 1e+4770 and 1e+4771.
1e+4770 is unimagineably big. The number of particles in the observable
universe is estimated to be between 1e+72 and 1e+87, so it would not be
possible to tally 1e+4770.
-- Bill
[email protected]
*
* 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/