benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
71 stars 18 forks source link

estout: missing leading zeroes in default number formatting #30

Closed MarcGillaizeau closed 3 years ago

MarcGillaizeau commented 3 years ago

Dear Ben,

I came across a small issue regarding the formatting of numbers whose absolute value is less than 1. The estout help file says that the default formatting for such numbers is to show a leading zero unless nolz is specified. It doesn't work when number format is left unspecified, or when the general format is specified:

clear set obs 10 g var = runiform() eststo test: estpost sum var estout test, cells(mean) estout test, cells(mean(fmt(g))) estout test, cells(mean(fmt(%g))) estout test, cells(mean(fmt(%9.0g)))

Note that it works as default for esttab unless the %g format is explicitly specified. In order to fix it, in the estout ADO file I added this bit to your vFormat program:

* For leading zeroes as default
if "`fmt'"=="%9.0g" & abs(`value') < 1 {
    local leadzero 0
    local value: di `leadzero' `fmt' `value'
    local value: di `value'
}
else local value: di `fmt' `value'
*local value: di `fmt' `value'

I inserted these lines right before you do:

local value: list retok value

It might not be the most elegant fix, but it sorts out the issue and I think it is stable. As far as I can tell there is no need to modify the SignificantDigits program.

Very best regards,

Marc

benjann commented 3 years ago

Hi Marc,

the current behavior is as intended. The purpose of nolz is to remove the leading zero that is printed by Stata in fixed format numbers (format %#.#f), because many journals use a style where the leading zero is omitted. By default, however, estout uses general format, where no leading zero exists in the first place, so nolz is irrelevant. I never had any intention to add a zero in this case.

I agree that the description of the option in the help file is not super clear. What it tries to say is that for fixed format numbers (and the "automatic" format, although this is not explicitly mentioned) the default is not to remove the leading zero. It does not try to say that the default is to add a zero.

ben