Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Precision and ordering issue in histograms titles


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Precision and ordering issue in histograms titles
Date   Thu, 25 Jan 2007 00:14:58 -0000

Another is to use value labels. Suppose you have 
groups of some variable that are 0.1, 0.2, 0.3, 0.4, 
0.5. 

We can mimic this with the auto data. 

. gen rep782 = rep78 / 10
(5 missing values generated)

Now map the distinct values to integers 1 ... 5 and 
label: 

. egen group = group(rep782), label
(5 missing values generated)

. tab group

group(rep78 |
         2) |      Freq.     Percent        Cum.
------------+-----------------------------------
         .1 |          2        2.90        2.90
         .2 |          8       11.59       14.49
         .3 |         30       43.48       57.97
         .4 |         18       26.09       84.06
         .5 |         11       15.94      100.00
------------+-----------------------------------
      Total |         69      100.00

If you don't like the labels, fix them manually: 

. label def  group 1 "0.1" 2 "0.2" 3 "0.3" 4 "0.4" 5 "0.5" , modify

. tab group

group(rep78 |
         2) |      Freq.     Percent        Cum.
------------+-----------------------------------
        0.1 |          2        2.90        2.90
        0.2 |          8       11.59       14.49
        0.3 |         30       43.48       57.97
        0.4 |         18       26.09       84.06
        0.5 |         11       15.94      100.00
------------+-----------------------------------
      Total |         69      100.00

Now a histogram: 

. histogram mpg, by(group)

Nick 
[email protected] 

Nick Cox
 
> One answer is to be found in a concurrent thread: 
> 
> . gen SX1 = string(X1, "%02.1f")
> 
> . twoway histogram mpg, by(SX1) 

MA V
  
> > Svend replied:
> > 
> > This is a precision problem. Try to declare X double precision:
> > 
> >    sysuse auto
> >    gen double X=0.8-foreign
> >    twoway histogram mpg , by(X)
> > -------------------------------------------------
> > 
> > Unfortunately in my case this does not seem to work...
> > Suppose you do
> > 
> > sysuse auto, clear
> > gen X=0.8-foreign
> > gen double X1=X
> > twoway histogram mpg , by(X1)
> > 
> > this still gives histograms with not so pretty titles...
> > 
> > How can I create histograms by X, with nice titles, and 
> > without losing the 
> > order of the histograms?

*
*   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