ARCHIVED: In Stata, how do I display numeric values with commas inserted?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

In Stata, the .format command inserts commas into a large numeric value to make it easier to read. For example, suppose a numeric variable gnp has a value of 12345678.9012, which is 13 characters long (including the decimal point). To insert commas into the numeric value, use this command:

  format gnp %15.4fc

This displays the variable as 12,345,678.9012. The f in the format indicates a real number, while c inserts commas after every three digits, starting from the decimal point and going left. You can also use g to indicate a general, and s to indicate a string. The variable xx in the format %xx.yy should be equal to or longer than the maximum character length of a value, including commas and a period; otherwise, the command will not work.

See below for more examples:

  format debt %12.2gc
  format name %25s

If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.

This is document axqn in the Knowledge Base.
Last modified on 2023-05-09 14:38:29.