How to Format Numbers Added with estadd in esttab
At a glance
- 1. Add a Numeric Scalar
Use estadd scalar to attach a numeric result to the current estimation results.
- 2. Store Each Model
Store the estimates after adding the scalar so the stored model includes it.
- 3. Format the Statistics Row
Use stats() and give fmt() a format for each statistic in the same order.
- 4. Format Coefficients Separately
Use cells() to control coefficient and standard-error formats.
When a table made with Stata’s esttab displays an added result with too many or too few decimal places, the key is to format the result according to where it appears. Coefficients and standard errors are formatted as table cells; scalars added to the estimation results are usually displayed as statistics rows.
Use estadd scalar for a numeric value, then specify its display format in the fmt() option of stats(). The format list follows the same order as the statistics named in stats().
Format added scalars with stats()
estadd scalar name = expression adds a numeric scalar to the current estimation results under name. To display it, include that name in esttab’s stats() list. Use fmt() in stats() to set its number format.
For example, fmt(0 3) means display the first listed statistic with zero digits after the decimal point and the second with three. If the statistics are N adjr2, the formats apply to N and adjr2, respectively.
Worked example
This example runs two regressions, adds each model’s adjusted R-squared as a scalar, stores the results, and formats the table:
sysuse auto, clear
regress price mpg weight
estadd scalar adjr2 = e(r2_a)
estimates store m1
regress price mpg weight foreign
estadd scalar adjr2 = e(r2_a)
estimates store m2
esttab m1 m2, ///
cells(b(fmt(3)) se(fmt(3))) ///
stats(N adjr2, fmt(0 3) ///
labels("Observations" "Adjusted R-squared"))
The coefficient and standard-error cells each display three decimal places. The statistics rows display the observation count as an integer and adjusted R-squared to three decimal places. The labels change the row headings, not the values or their formats.
The order matters: stats(N adjr2, ...) is paired with fmt(0 3). If you reverse the statistics, reverse the formats too. If you add another statistic, include a corresponding format in fmt() when you want to control its display explicitly.
Keep coefficient and statistic formats separate
A common source of confusion is applying a coefficient format and expecting it to affect an added scalar. The two parts of the table use different options:
| Table content | Typical formatting option |
|---|---|
| Coefficients and standard errors | cells() options such as b(fmt(3)) and se(fmt(3)) |
Statistics such as N, R-squared, or an added scalar | stats() with fmt() |
For example, b(3) or cells(b(fmt(3))) controls coefficients; it does not set the number of decimal places for an added statistic. Conversely, stats(..., fmt(...)) does not determine how coefficient estimates are printed.
If you use esttab’s simpler coefficient options, you can still format statistics separately:
esttab m1 m2, b(3) se(3) stats(N adjr2, fmt(0 3))
Use either coefficient-format syntax that suits your table, while keeping the statistics format in stats().
Numeric scalars versus text
Use estadd scalar when the added value is numeric and should be formatted as a number. For instance:
estadd scalar my_ratio = 1.23456
You can then display my_ratio through stats(my_ratio, fmt(2)) to show two digits after the decimal point.
estadd local is for text, such as a note indicating whether a model includes a particular set of controls. Since that value is a string rather than a numeric scalar, a numeric fmt() setting does not round or reformat it. Choose estadd scalar for quantities and estadd local for text labels or other string values.
Common mistakes
- Formatting the wrong part of the table: A setting for
b()orse()will not format a statistic row. Put the format for an added scalar instats(). - Mismatching the format order: Each format corresponds positionally to a statistic in
stats(). Check that the names and formats are listed in the same intended order. - Using a local for a number: A value added as text cannot be rounded with a numeric display format. Store numeric quantities as scalars.
- Storing the model too early: Add the scalar before storing the estimation results, so the stored model contains the added value. If you modify stored results later, verify that the scalar is present in the estimates passed to
esttab. - Confusing display with calculation:
fmt()changes how a value is printed; it does not change the stored estimate or its precision.
If a statistic still appears unexpectedly, check that its name is present in the stored estimates and spelled the same way in stats(). Also verify that formats are applied in the intended order; a single format can be specified for all statistics, while multiple formats can assign different formats positionally.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.