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

Rounding issue #2

Open
angelokisilmarino opened this issue Jun 6, 2022 · 7 comments
Open

Rounding issue #2

angelokisilmarino opened this issue Jun 6, 2022 · 7 comments

Comments

@angelokisilmarino
Copy link

Hi, thanks for your great work! I am having an issue with some coefficients that are not rounding as expected. I am trying to round to 3 decimal places, but the command is exporting some coefficients with 16 decimal places. It does round to 3 decimal places as expected, but fills in up to the sixteenth with 12 zeros and a 1 at the end.

@acarril
Copy link
Owner

acarril commented Jun 15, 2022

Hi, sorry it took me so long to reply. Based on what you describe, it seems like bug induced by floating points. I'll take a closer look and report back.

@acarril
Copy link
Owner

acarril commented Jun 15, 2022

Could you please provide a minimum working example so that I can reproduce the issue?

@angelokisilmarino
Copy link
Author

angelokisilmarino commented Jun 21, 2022

Hi, thanks for answering. The following example reproduces the rounding issue I reported here:

sysuse auto, clear

reg mpg trunk foreign

texresults using results.tex, texmacro(trunk) coef(trunk) unitzero replace

@acarril
Copy link
Owner

acarril commented Jun 21, 2022

Unfortunately I am not able to reproduce the issue you describe. When running your example above, I get

% results.tex
\newcommand{\trunk}{$-0.68$}

which is the expected behavior: the result has a zero in the unit position, and it is rounded to two decimal places, which is the default. I am using Stata/MP 17.0 for Mac (Intel 64-bit), revision 01 Jun 2022. Below is a screenshot of what I run and the output I get.

image

@angelokisilmarino
Copy link
Author

Indeed, it may be a version problem then, when I run on Stata 15, I get the output copied below. However, when I run on Stata 17, I get -0.68, just like you. I am sorry for that.

image

@acarril
Copy link
Owner

acarril commented Jun 22, 2022

I see, no need to apologize! I presume it must be that the round() function works differently for different Stata versions. Unfortunately I don't have access to Stata 15 to try to debug this, so unless you're able to find a solution, it is unlikely that I'll be able to fix this issue on my end.

@gns36
Copy link

gns36 commented May 22, 2023

Hi! Thanks again for creating this package. I am having a similar rounding issue but slightly different circumstance. I am using matrices to create the lower and upper bounds on my coefficients and then also export those using texresults. However, one of my bounds also has the same rounding issue. I have tried exporting the contents from the matrix as a local, and also rounding the matrix itself. I also updated to stata18 but am still having this issue. Here is some code that recreates the issue:

`//recreate issue using auto data
sysuse auto, clear
reg mpg trunk foreign

//create matrices to find lower and upper bounds
mat var = e(V)
local v = var[1,1]
mat se = sqrt(var[1,1])
mat B = e(b)
mat b = B[1,1]
mat lb = b-num*se

//export results
texresults using results.txt, texmacro(lb) result(lb[1,1]) unitzero replace
cat results.txt`

The results show: \newcommand{\lb}{$-0.9500000000000001$}
instead of \newcommand{\lb}{$-0.95$}

Any help solving this issue would be greatly appreciated. Thank you for your time.

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

3 participants