Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Rounding problem in graph

From   Friedrich Huebler <>
Subject   st: Rounding problem in graph
Date   Thu, 11 Sep 2003 14:04:27 -0700 (PDT)

This is an excerpt from a larger data set:

     sex   rg5      order       tmax       mmax       fmax
    Male  72.2          2       74.9       72.2       74.9
  Female  74.9          1       74.9       72.2       74.9

I want to draw a simple bar graph that indicates the value for each
sex. The problem is that I cannot find a way for Stata to draw the
value for Female (74.9) rounded to one decimal place. Instead, the
number 74.90000000000001 is drawn.

  #delimit ;
  local textpos1 = tmax/100*20;
  local textpos2 = tmax/100*50;
  local mvalue = round(mmax,.1);
  local fvalue = round(fmax,.1);
  graph bar rg5,
    over(sex, sort(order) gap(0) axis(off))
    bar(1, bcolor(0 153 255) blcolor(white))
    yscale(r(0 `max(tmax)') off) ylabel(minmax, nogrid)
    outergap(0) plotr(m(zero))
    graphregion(color(white) margin(zero))
    text(`textpos1' 25 "Girls", size(20) color(white))
    text(`textpos1' 75 "Boys", size(20) color(white))
    text(`textpos2' 25 "`fvalue'%", size(20) color(white))
    text(`textpos2' 75 "`mvalue'%", size(20) color(white))

When the line

  local fvalue = round(fmax,.1);

is changed to

  local fvalue = round(fmax,1);

a rounded value is displayed. When 74.8888 is substituted for 74.9 in
fmax, it is possible to round to two or three decimal places, but not
to one decimal place. How can I make Stata display exactly 74.9 in
the graph?

Many thanks,

Friedrich Huebler

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index