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

st: Re: Marker labels with background color


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Re: Marker labels with background color
Date   Wed, 2 Feb 2005 08:20:32 -0800 (PST)

Thank you, Scott and Nick. Thanks to your help I can now draw a graph
with proper labels.

#delimit ;
sysuse uslifeexp, clear;
keep if year>1918 & year<1925;

forval i = 1/6 {;
  local le: di %4.1f `=le[`i']';
  local tbox "`tbox' text(`=le[`i']' `=year[`i']+0.05'
    "`le'", box bc(white) place(e) size(small))";
  local le_male: di %4.1f `=le_male[`i']';
  local mbox "`mbox' text(`=le_male[`i']-0.2' `=year[`i']'
    "`le_male'", box bc(white) place(s) size(small))";
  local le_female: di %4.1f `=le_female[`i']';
  local fbox "`fbox' text(`=le_female[`i']+0.2' `=year[`i']'
    "`le_female'", 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.3)) yscale(r(53 62.5));

Friedrich

--- Nick Cox <[email protected]> wrote:
> 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 
> [email protected] 
> 
> 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));


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index