Dear Statalists,
I came across an error when I tried to display a local macro. As you can see in the output below, there is an error when I display local macro X under " " after rounding it to 2 decimal places. Stata displays several fake 0s and one 1. This, however, does not happen when I change to 3 decimal places, display the local macro without " ", or display another local macro Y in the same way. I know the best solution is to round to 3 decimal places, but I'm still curious about why Stata gave me results below.
I'm using Stata/MP 19.0 (current update level : 07 May 2025)
Kind regards,
Yugen
I came across an error when I tried to display a local macro. As you can see in the output below, there is an error when I display local macro X under " " after rounding it to 2 decimal places. Stata displays several fake 0s and one 1. This, however, does not happen when I change to 3 decimal places, display the local macro without " ", or display another local macro Y in the same way. I know the best solution is to round to 3 decimal places, but I'm still curious about why Stata gave me results below.
I'm using Stata/MP 19.0 (current update level : 07 May 2025)
Kind regards,
Yugen
Code:
. ** Summarize X
.
. su X , meanonly
. di r(mean)
-92.958839
.
. * 2 decimal places
.
. local X =round(r(mean),0.01)
. di `X'
-92.96
. di "`X'"
-92.96000000000001
. * 3 decimal places
. local X =round(r(mean),0.001)
. di `X'
-92.959
. di "`X'"
-92.959
.
. ** Summarize Y
.
. su Y , meanonly
. di r(mean)
-98.908394
.
. * 2 decimal places
.
. local Y =round(r(mean),0.01)
. di `Y'
-98.91
. di "`Y'"
-98.91
Comment