Announcement

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

  • Generating Histogram (Bin and Frequency) Variables

    Hello Statalist,

    The figure shows the frequency of the numbers of taxpayers for each taxable income bin (the bin width=1000).
    Now, I want to generate bin (again the bin width=1000) variable and the frequency variable (which shows the number of taxpayers for each bin).

    How can I do that?

    Thank you in advance.

    Best,
    Beyza

  • #2
    Generate them from what? What is the data you have to start with? Please show a sample using -dataex-.

    Comment


    • #3
      id year z mtr
      99953 3 43659.46 .2 0
      99954 3 97996.84 .4 0
      99955 3 96.13873 .2 0
      99956 3 30910.6 .2 0
      99957 3 17263.184 .2 0
      99958 3 20324.7 .2 0
      99959 3 25256.91 .2 0
      99960 3 4774.516 .2 0
      99961 3 8024.386 .2 0
      99962 3 24740.604 .2 0
      99963 3 25636.916 .2 0
      99964 3 35088.46 .2 0
      99965 3 6207.52 .2 0
      99966 3 50665.61 .4 0
      99967 3 2120.4077 .2 0
      99968 3 6724.982 .2 0
      99969 3 28625.344 .2 0
      99970 3 6398.885 .2 0
      99971 3 37912.56 .2 0
      99972 3 11393.706 .2 0
      99973 3 16853.871 .2 0
      99974 3 1924.1968 .2 0
      99975 3 0 0 0
      99976 3 16973.586 .2 0
      99977 3 15196.46 .2 0
      99978 3 2680.253 .2 0
      99979 3 23299.83 .2 0
      99980 3 57615.78 .4 0
      99981 3 61745.2 .4 0
      99982 3 13617.713 .2 0
      99983 3 12316.514 .2 0
      99984 3 9725.373 .2 0
      99985 3 25840.19 .2 0
      99986 3 3862.949 .2 0
      99987 3 1348.3853 .2 0
      99988 3 25636.297 .2 0
      99989 3 35864.195 .2 0
      99990 3 15553.306 .2 0
      99991 3 35624.535 .2 0
      99992 3 1669.6044 .2 0
      99993 3 2909.124 .2 0
      99994 3 37313.64 .2 0
      99995 3 19722.68 .2 0
      99996 3 20200.236 .2 0
      99997 3 48306.29 .2 0
      99998 3 10522.91 .2 0
      99999 3 4759.096 .2 0
      100000 3 48400.18 .2 0


      That is from my data set.
      The first one is id number of taxpayers (total:100.000), second one is year 3 third one is z: taxable income and the last column is mtr (marginal tax rate). So first I plot histogram of taxable income for year 3, including only taxpayers with z between 10000 and 1000000 with the bin width 10000. (vertical axis is frequency). Now I want to create bin variable and frequency (the frequency count of the number of taxpayers in each bin) variable . I hope I am clear now and you understand my question.


      Comment


      • #4
        OK. Try this:

        Code:
        gen bin_num = floor(z/10000)
        contract bin_num, freq(frequency)
        gen bin_lower = 10000*bin_num
        gen bin_upper = 10000*bin_num + 9999

        Comment


        • #5
          Clyde solved the problem nicely. See also

          http://www.stata-journal.com/sjpdf.h...iclenum=gr0014

          http://www.statalist.org/forums/foru...stogram-values

          http://www.statalist.org/forums/foru...oway-bar-graph

          Top tip: you shouldn't believe that you are the first person to want to know this. So do search for previous posts or papers.

          Comment


          • #6
            Great! That worked. Thank you.

            Comment

            Working...
            X