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

  • Can I make a histogram's axis a log axis while ensuring the bins are equal log width?

    I want to create a histogram with data on wage, and have the x-axis a log axis. Can I have the bins of the histogram equal log width so that they look like they have the same width on the graph? I have already generated the log wage variable from the wage variable. If I use the log wage variable, the x-axis will display as a log variable, but I think it will look better to have the actual wage displayed on the axis. Alternatively, I can achieve the same purpose by using the log wage variable but then somehow displaying the x-axis as the actual wage. Can you help?

  • #2
    I've often wanted this but always worked ad hoc. The only method I know is do everything on log scale but let the axis labels show the original scale. It's hard to do this cleanly unless your bin limits are integer powers of 10 (or 2, arguably), so far as I can see.

    Some technique:

    set obs 1000
    set seed 2803  
    gen y = exp(rnormal(7, 2.5))
    su y
    label var y "Whatever"
    gen logy = log10(y)
    su logy
    * prior -ssc inst mylabels- required for this to work
    mylabels 1 10 100 1000 1e4 1e5 1e6, myscale(log10(@)) local(xla)
    histogram logy, width(1) start(-1) xtitle("`: var label y'") xla(`xla') ///
    bfcolor(ltblue) blcolor(ltblue*2)
    EDIT: A variant is to have widths 0.5 and then label every other bin limit, etc.
    Last edited by Nick Cox; 14 Sep 2017, 07:33.


    • #3
      I managed to do it by adding individual ticks and labels in the graph editor (using a calculator to find what ln(10), ln(100), ln(1000) etc are):

      Click image for larger version

Name:	Graph2.png
Views:	1
Size:	28.2 KB
ID:	1410374

      I know I'm going to ask another question now, so tell me if I need to start a new topic. How can I get a line showing the mean or median of each distribution?


      • #4
        help added line options


        • #5
          I don't know how to switch between the graph editor and the graph's code. Can you tell me how I can get the code for my graph once I have edited it in the graph editor, so that I can edit it using code?


          • #6
            The help for the Graph Editor includes comments on the Graph Recorder.

            That said, I would always add a line using command syntax in the first place.