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

st: RE: RE: Re: Marker labels with background color


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Re: Marker labels with background color
Date   Wed, 2 Feb 2005 13:51:53 -0000

This is the old binary-decimal precision 
issue again. Most multiples of 0.1 cannot 
be held exactly as binary numbers. 

The most direct solution is possibly to run a number 
-- let's say in the local macro `foo' -- 
through 

local foo : di %2.1f `foo' 

to ensure that the text is what you want. 

I'd leave the original variables untouched. 

Nick 
n.j.cox@durham.ac.uk 

Scott Merryman
 
> Friedrich,
> 
> The -round()- function inside the text() option will almost 
> give you what
> you want.  For some reason, -round(le_male[`i'],.1)- for the 
> year 1922 gives
> "54.40000000000001" rather than 54.4, hence the use of -tostring- for
> le_male.
> 
> 
> #delimit ;
> sysuse uslifeexp, clear;
> keep if year>1918 & year<1925;
> 
> tostring le_m , gen(lem2) format(%3.1f) force;
> 
> forv i = 1/6 { ;
>   local tbox "`tbox' text(`=le[`i']' `=year[`i']+0.05'
>     "`=round(le[`i'],.1)'", box bc(white) place(e) size(small))";
> 
>   *local mbox "`mbox' text(`=le_male[`i']-0.2' `=year[`i']'
>     "`=round(le_male[`i'],.1)'", box bc(white) place(s) size(small))";
> 
>   local mbox "`mbox' text(`=le_male[`i']-0.2' `=year[`i']'
>     "`=lem2[`i']'", box bc(white) place(s) size(small))";
> 
>   local fbox "`fbox' text(`=le_female[`i']+0.2' `=year[`i']'
>     "`=round(le_female[`i'],.1)'", box bc(white) place(n) 
> size(small))";
>   };
> 
> scatter le year, connect(l) `tbox' ||
>   scatter le_male year, connect(l) `mbox' ||
>   scatter le_female year, connect(l) `fbox'
>   xscale(r(1918.8 1924.2)) yscale(r(53 63));

Friedrich Huebler
 
> > Thank you for your response to my query. I like your suggestion to
> > use the -text(, box)- option. Below is a good example for 
> the kind of
> > graph that I am actually trying to create. I have three timelines
> > (total, male, and female) and the points are sometimes so close to
> > each other that I cannot draw the labels on top of the marker. This
> > is solved by adding the -place()- option.
> > 
> > I also found that at the default position of the textbox the markers
> > are partially covered. My solution is to add or subtract a certain
> > amount from the coordinates of the marker. This amount 
> depends on the
> > scale of the x- and y-axes.
> > 
> > I am left with one problem for which I have no solution. I 
> would like
> > the labels to appear in the format %4.1f but the number 61.8, for
> > example, appears as 61.79999923706055 in the textbox. I 
> tried setting
> > -format le le_male le_female %4.1f- but this has no effect on the
> > graph.
> > 
> > #delimit ;
> > sysuse uslifeexp, clear;
> > keep if year>1918 & year<1925;
> > forv i = 1/6 {;
> >   local tbox "`tbox' text(`=le[`i']' `=year[`i']+0.05'
> >     "`=le[`i']'", box bc(white) place(e) size(small))";
> >   local mbox "`mbox' text(`=le_male[`i']-0.2' `=year[`i']'
> >     "`=le_male[`i']'", box bc(white) place(s) size(small))";
> >   local fbox "`fbox' text(`=le_female[`i']+0.2' `=year[`i']'
> >     "`=le_female[`i']'", box bc(white) place(n) size(small))";
> >   };
> > scatter le year, connect(l) `tbox' ||
> >   scatter le_male year, connect(l) `mbox' ||
> >   scatter le_female year, connect(l) `fbox'
> >   xscale(r(1918.8 1924.2)) yscale(r(53 63));
> > 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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