Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Undesirable formatting of axis labels when value labels are present

    I'm getting some behavior that I don't expect regarding the formatting of axis labels. In certain circumstances, the axis labels are pretty round numbers, and in other circumstances, they are ugly almost-round numbers that are shifted by what appears to be a floating-point amount.

    Code:
    pause on
    
    clear
    
    input x
    0.5
    1
    end
    
    hist x // Axis labels are pretty
    pause // Enter q to continue execution
    
    format %65.0g x
    hist x // Axis labels are ugly
    pause
    
    format %9.0g x
    hist x // Axis labels are pretty again
    pause
    
    label define elephant .e "Missing because an elephant sat on it and it got kind of squished"
    label value x elephant // format of x becomes %65.0g automatically
    hist x // Axis labels are ugly again
    pause
    
    format %9.0g x
    hist x // Axis labels are ugly still
    pause
    
    label value x // Remove the value label
    hist x // Axis labels are pretty again
    pause
    
    label value x elephant, nofix // nofix prevents format of x from changing
    hist x // Axis labels are ugly again
    
    pause off
    1. In every case, Stata should be smart enough to figure out that the axis labels should be displayed as ".2" etc. After all, Stata is the one choosing these labels. Let's leave that to one side.
    2. What is it about the presence of a value label that causes the axis label formatting to fail, even when the variable format is "correct"?
    3. As a workaround, is there a way of coercing axis label formatting to work properly without dropping the value label?

  • #2
    1. But you are telling Stata to display the axis labels at %65.0g. The axis label value .55 is being displayed as .55000000000000004
    Code:
    . disp %65.0g .55
                                                   .55000000000000004
    3. You could use a format statement suboption in the xlabel() option

    Comment


    • #3
      1. How am I doing this? What about my code is telling the axis labels to be formatted as %65.0g? It's not the format of the variable; note that label value x elephant, nofix still messes up the labels. Also note that graph twoway scatter x x does not always format the axis labels with the same format as hist x.

      3. This is a good workaround. Thanks.

      Comment

      Working...
      X