In Stata, how do I calculate the factorial of a natural number n?
The Stata lnfactorial(n) function returns the
natural log factorial of n, i.e. ln(n!). This function avoids overflow
errors when n is large.
Suppose you wish to calculate the factorial of 9. You can get the
factorial using the functions round() and
exp() to transform the output of
lnfactorial().
Note: The .di command is an abbreviation of
.display. The round() function requests that
Stata round the result to the nearest whole number.
For more about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.
Last modified on May 06, 2011.







