Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

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().

. display lnfactorial(9) 12.801827 . di exp(lnfactorial(9)) 362880 . di round(exp(lnfactorial(9)),1) 362880

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.

This is document aupp in domain all.
Last modified on May 06, 2011.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.