David Schriger writes:
> Would someone be kind enough to explain to me why the following
calculation
> produces a number when I use "15" but produces a missing for values > 18.
> This occurs whether I am doing a 'display' or 'generating' a variable.
>
> . di 9^140*(15^139)*exp(-9*15)/exp(lnfact(139))
> .28701151
>
> . di 9^140*(19^139)*exp(-9*19)/exp(lnfact(139))
> [no output produced]
Stata performs numeric operations from left to right following its rules for
the hierarchy of operators. Given those rules, it likely calculates 9^140,
then calculates 19^139, then multiplies them together. At that point, the
value exceeds the largest number that can be handled by the internal
precision used in Stata and a missing value is returned (you indicate "no
output produced" but I'm sure it returns the missing code, a period). If
you rearrange your calculation so you divide earlier (thus keeping the
number within the internal storage range), you will get the correct answer:
. di 9^140 / exp(lnfact(139)) * (19^139) * exp(-9*19)
.01239834
Note that I moved the "/ exp(lnfact(139))" term from the end to the "second"
position among the multiply and divide terms.
Tom
*
* 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/