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

# st: trying to round values and store in a macro, problem with double/floating precision number storage

 From Woolton Lee To statalist Subject st: trying to round values and store in a macro, problem with double/floating precision number storage Date Thu, 5 May 2011 11:44:23 -0400

```Hello,

I have a program which creates descriptive statistics using tab1,
summarize and other functions, stores the macros then posts them using
postfile and creates tables that can be cut and pasted easily into a
word document.

For example, a small segment of my program is as follows,

/* continuous variables  - CRC */
local vars2 age los tchg costpd rbchg rcchg scchg aneschg phrchg radchg mrict
nmchg clchg orchg msschg othchg;

forvalues x = 1/16 {;
local v: word `x' of `vars2';
/********* insurance by safety net hospital */
forvalues a = 1/4 {;
local i: word `a' of `ins';
sum `v' if vhi_site == "Colorectal" & `i' == 1 & snh == 1;
gen float mn = round(r(mean),0.01);
gen float sd = round(r(sd),0.01);
sum mn;
local mn`v'_snh`i'= r(mean);
sum sd;
local std`v'_snh`i' = r(sd);
drop mn sd;
};

This loop creates the variables mn and sd and rounds the result of the
numbers I want to two decimal places then uses summarize to store
these values into macros.  I wonder if there is another more efficient
way to do this?  I originally was doing all of the computations with
only macros but I found that I could not round to two decimals without
running into problems where a number like 55.87000000000000000001
would show up in my tables.  Is there anyway to make this work doing
the computations with just macros?