Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: different ways to display coefficient digits in etable #82

Closed
lyifa opened this issue Jan 6, 2021 · 12 comments
Closed

Comments

@lyifa
Copy link

lyifa commented Jan 6, 2021

The LaTex output of etable shows an inconsistent number of decimal places for estimated coefficients, t values, and R squared values. Specifically, some of my coefficients have 1 decimal place while the others have about 4. The t values also show this inconsistent pattern. Meanwhile, the R squared values have 7 decimal places.

In my area (accounting and finance), all journal papers require numbers to have the same decimal places.

@lrberge lrberge changed the title A possible bug Feature request: different ways to display coefficient digits in etable Jan 6, 2021
@lrberge
Copy link
Owner

lrberge commented Jan 6, 2021

That's not a bug, it's a choice. The argument digits refers to the number of significant digits (I've just clarified the help) and I chose not to affect the statistics which have their own formatting.

Since you're not the only one requesting this feature, I'll see what I can do. But it won't be before a while, so maybe you could use modelsummary instead?

@lyifa
Copy link
Author

lyifa commented Jan 6, 2021

Thanks for the clarification. I understand this is a choice.
I think I will stick to the plm package for a while before this feature is implemented in fixest.

@lrberge
Copy link
Owner

lrberge commented Jan 7, 2021

Sure. I'm letting the issue open until the feature is added.

@lyifa
Copy link
Author

lyifa commented Jan 7, 2021

One more thing, I noticed that some R- squared values use scientific notation while others don't. I am not sure if this is also a choice.

@waynelapierre
Copy link

I also encountered the scientific notation issue. Hopefully, the etable function will be refined. This seems to be the only factor keeping people from using it in place of plm and/or lfe.

@lrberge
Copy link
Owner

lrberge commented Jan 8, 2021

So here's an update: I've added a different way to display the decimals.
To have a fixed number of decimals, use the code digits = "rd" with d the number of digits: e.g. digits = "r2" will round at the second decimal and will always show two decimals--no more, no less.

I have separated the display for the fit statistics, now there's the new argument digits.stats. I also took the advantage to speed up the code.

Here's an example of the new behavior:

n = 1e3
base = data.frame(x1 = rnorm(n), x2 = rnorm(n))
base$y = base$x1 / 1000 + 10*base$x2 + rnorm(n, sd = 150)

res1 = feols(y ~ x1, base)
res2 = feols(y ~ I(1000*x1) + x2, base)

etable(res1, res2, digits = 2)
#>                       res1          res2
#> Dependent Var.:          y             y
#>                                         
#> (Intercept)     -4.4 (4.8)    -4.2 (4.8)
#> x1               5.5 (5.1)              
#> I(1000 x x1)               0.005 (0.005)
#> x2                             4.1 (5.1)
#> _______________ __________ _____________
#> S.E. type         Standard      Standard
#> Observations         1,000         1,000
#> R2                   0.001         0.002
#> Adj. R2             0.0002       -0.0001
etable(res1, res2, digits = "r2")
#>                         res1         res2
#> Dependent Var.:            y            y
#>                                          
#> (Intercept)     -4.39 (4.76) -4.16 (4.77)
#> x1               5.55 (5.08)             
#> I(1000 x x1)                  0.01 (0.01)
#> x2                            4.10 (5.07)
#> _______________ ____________ ____________
#> S.E. type           Standard     Standard
#> Observations           1,000        1,000
#> R2                     0.001        0.002
#> Adj. R2               0.0002      -0.0001
etable(res1, res2, digits = "r2", digits.stats = "r2")
#>                         res1         res2
#> Dependent Var.:            y            y
#>                                          
#> (Intercept)     -4.39 (4.76) -4.16 (4.77)
#> x1               5.55 (5.08)             
#> I(1000 x x1)                  0.01 (0.01)
#> x2                            4.10 (5.07)
#> _______________ ____________ ____________
#> S.E. type           Standard     Standard
#> Observations           1,000        1,000
#> R2                      0.00         0.00
#> Adj. R2                 0.00        -0.00

setFixest_etable(digits = "r2", digits.stats = 2)
etable(res1, res2)
#>                         res1         res2
#> Dependent Var.:            y            y
#>                                          
#> (Intercept)     -4.39 (4.76) -4.16 (4.77)
#> x1               5.55 (5.08)             
#> I(1000 x x1)                  0.01 (0.01)
#> x2                            4.10 (5.07)
#> _______________ ____________ ____________
#> S.E. type           Standard     Standard
#> Observations           1,000        1,000
#> R2                     0.001        0.002
#> Adj. R2               0.0002      -0.0001

The default behavior for digits is actually not exactly to display the first digits significant digits. It's the outcome of an algorithm that I have now detailed in the help pages.

It's in the dev branch but I'll submit the new version to the CRAN next week.

@lyifa
Copy link
Author

lyifa commented Jan 8, 2021

Thanks for the update! Have you looked into the R squared value scientific notation issue?

@lrberge
Copy link
Owner

lrberge commented Jan 8, 2021

Yes, it was due to the initial format displaying many digits for the statistics--it has been naturally solved by the introduction of the new argument digits.stats.

Now the scientific notation will still be popping but only when digits is not round and |x| < 1e-5 (so it should be rare). But then the threshold at which it appears can be set with the powerBelow argument.
Note though that for very large numbers, i.e. |x| > 1e10 (like the likelihoods for instance), scientific notation will pop and there's no way around it (I really don't think it's readable without it anyway).

@lrberge
Copy link
Owner

lrberge commented Jan 11, 2021

Just to say that I'll submit to the CRAN this week, so if you have any other comment/suggestion on that issue I'll try to implement them before submission.

@lyifa
Copy link
Author

lyifa commented Jan 11, 2021

I have tested it extensively. It works well.

@lrberge
Copy link
Owner

lrberge commented Jan 11, 2021

Great then, I'll let it that way.

@lrberge lrberge closed this as completed Jan 11, 2021
@maswiebe
Copy link

It seems that powerBelow overrides digits='sd', but not digits='rd'.

When I use digits='r4', powerBelow=-9, very small numbers show up as 0.0000.

But when I use digits='s4', powerBelow=-9, the small number shows up as 0.00000005.

Ok, I see you have the rule:

For numbers lower than 1 (in absolute terms), the number of decimals displayed is equal to digits except if there are only 0s in which case the first significant digit is shown.

I'd prefer to see 0.0000 instead of scientific notation or 0.00000005. I don't want to use digits='rd' in this case because I have some large coefficients where four decimal places is awkward, eg. I want 5001.6 instead of 5001.6245.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants