Announcement

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

  • Stata histogram problem

    Hi there,

    I haven't ever made any histogram from Stata actually, and I am facing some problem the first time I am attempting it.

    I have a column with log(income), and most of the values are between 8 and 10 (they are not integers). When I tried to use the toolbar/boxes to create histogram, I used "logincome" for the frequency weight option. But it gave the message that it cannot make a histogram because logincome is not an integer. If I turn them into integer, then the crucial differences in decimals will be lost, and the histogram will mostly have even height of bars. Any suggestion on this?

    What I am trying to do is to graph in histogram the average logincome of all counties of a US state for a specific year. For the counties, I am using county numeric identifiers.

    Thanks a lot for the help

  • #2
    log(income) is not a weight, it is just the main variable you want to create a histogram for. So here is an example that will work just fine:

    Code:
    sysuse nlsw88, clear
    gen lnwage = ln(wage)
    hist lnwage
    I actually find it easier to interpret wage than log(wage), but I do want to keep the log-scale for the x-axis, so I want to keep the scale, but change the labels. So continuing the example:

    Code:
    hist lnwage ,                ///
        xlab(`=ln(1.25)'  "1.25" ///
             `=ln(2.5)'   "2.5"  ///
             `=ln(5)'     "5"    ///
             `=ln(10)'   "10"    ///
             `=ln(20)'   "20"    ///
             `=ln(40)'   "40")   ///
        xtitle("hourly wage (log scale)")
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks a lot.

      But I am still getting weird results.

      I have data something like this:

      county_no | year | realinc | realinc_log

      1 | 1970 | 13466 | 9.506
      1 | 1971 | 13856 | 9.565
      1 | 1972 | 14886 | 9.608

      2
      2
      2

      3
      3
      3

      ..
      ..
      ..

      100
      100
      100

      So I have 100ish counties spread in a long format. What I am trying to do is to make a histogram for the realinc_log for all counties of the state for the year 1970.

      Could you please help me with that? Thanks!
      Last edited by Samyam Shrestha; 26 Sep 2018, 01:55.

      Comment


      • #4
        For the real income absolute, I used this syntax:

        histogram county_no if year==1970 [fweight = realincint], discrete frequency

        And the histogram looks correct. Is it right?

        Comment


        • #5
          Code:
          search niceloglabels
          in an up-to-date Stata for a community-contributed command and an associated Stata Journal article.

          Comment


          • #6
            Originally posted by Samyam Shrestha View Post
            For the real income absolute, I used this syntax:

            histogram county_no if year==1970 [fweight = realincint], discrete frequency

            And the histogram looks correct. Is it right?
            I do not understand why you insist on using income as a weight, when we already established that that is wrong. In all likelihood, what you want is:

            Code:
            histogram realinc_log if year==1970, frequency
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              If you want a bar chart of income for each country. Use graph hbar. Better yet, use graph dot.

              Here is some technique:

              Code:
              sysuse auto, clear
              
              graph hbar (asis) mpg if foreign, over(make, sort(1) descending)
              
              graph dot (asis) mpg if foreign, over(make, sort(1) descending)
              
              graph dot (asis) mpg if foreign, over(make, sort(1) descending) linetype(line)   lines(lc(gs12) lw(vthin))
              Detail: The dotted grid lines that are default with graph dot look fine in Stata but in my experience often seem to get mangled on transport beyond Stata. On that and other grounds, travel the extra mm and call up very thin, light gr{e|a}y lines as a grid.

              Comment

              Working...
              X