Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: rounding the minimum of a negative number

From   annoporci <>
To   "" <>
Subject   st: rounding the minimum of a negative number
Date   Thu, 10 Jan 2013 03:59:29 +0800

Dear Statalist,

This is a problem for which I have found a solution. I am sending this to
Statalist for the record and/or further discussions if warranted.

I have data whose minimum is something like -1.9810 which I want to
"transform" into -1.9900. By "transform" I mean that I want to "floor" it
to the nearest smaller rational number with 2 non-zero decimal digits.

The -round(x,y)- function takes 2 arguments that allow you to select the
precision of the rounding. But the rounding is to the nearest greater
rational number. The -floor- function takes only 1 argument and "floors"
to a natural number without decimal digits. Or that is what I gather from
Stata help. Perhaps there is some undocumented extension to floor or some
more general function by another name?

Thus, using -round- on -1.9810 yields -1.98. There does not seem to be an
option to make -round- act like -floor-. Here is my workaround to this
shortcoming (rather obvious, I know):

scalar m = floor(100*r(min))/100

Is that the state of the art?

I must admit that along the way, I observed some unexpected behaviour,

set obs 10
gen x = -1.98100
sum(x), meanonly
scalar min1 = "`r(min)'"
scalar min2 = r(min)
scalar list
              min2 = -1.9809999
              min1 = -1.980999946594238

I did not expect -1.98100 to "become" (or appear so): -1.980999 or

It looks like something to do with the idea that -1.98100 and -1.98109 are
treated as the same number at the level of precision Stata assumes I'm
interested in.

Patrick Toche.
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index