Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: leading zeros with decimals

From   "Martin Weiss" <>
To   <>
Subject   st: AW: leading zeros with decimals
Date   Thu, 22 Apr 2010 17:45:35 +0200


Note -help format- on this issue:

"In %w.df, w is the total output width, including sign and decimal point,
and d is the number of digits to appear to the
    right of the decimal point."

"w" is thus the sum of the digits to the left and right, plus decimal


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Ann Owens
Gesendet: Donnerstag, 22. April 2010 17:41
Betreff: st: leading zeros with decimals


I have data that need to be formatted with leading zeros and decimal
places. Specifically, I need 4 digits before the decimal and 2 after.
According to the Stata help file for format, I should be able to
achieve this through:

format var %04.2f

However, this does not add leading zeros. It seems like something with
the decimal is throwing it off, because using %04.0f will give me
leading zeros. I've also tried:

gen str7 newvar=string(var, "%04.2f")

with no success (again, no leading zeros). Any suggestions?

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index