Announcement

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

  • bar chart width of bars

    Hi i created this bar chart using the bar chart option within the data tab in stata and i produced this:
    Click image for larger version

Name:	Screenshot 2019-05-02 at 11.46.37.png
Views:	1
Size:	39.5 KB
ID:	1496210


    the data for my income predictor is as follows:
    Code:
    Example generated by -dataex-. To install: ssc install dataex
    clear
    input double p344p
    615.33
    602.11
    1735.59
    876
    1228.814
    713.184
    253.15
    1956.725
    730.41
    194.9
    741.76
    379.2507692307692
    1536.57
    1269.43
    314.394
    1343.825
    661.7158974358974
    655.1025
    680.462
    536.8
    196.142
    309.69
    562.302
    514.62
    1119.865
    404.152
    144.042
    512.992
    682.44
    303.48
    540.27
    1956.725
    332.252
    564.6265
    734.052
    1956.725
    194.914
    197.912
    507.115
    507.55
    406.56
    356.869
    696.885
    390.3
    1004.0153846153846
    466.38
    1956.725
    955.5225
    330.424
    919.78
    888.65
    1020.8195
    601.584
    665.37
    86.5
    748.27
    292.894
    960.974
    552.072
    732.46
    660.142
    452.25
    442.574
    495.4175
    721.15
    74.77
    593.96
    392.34
    481.042
    252.35
    518.07
    387.03
    1956.725
    991.28
    359.732
    820.074
    154.002
    559.52
    148.122
    810.04
    150.192
    472.51935897435897
    1307.8
    363.752
    1044.97
    180.78
    1892.695
    291.062
    1072
    676.71
    713.75
    772.292
    886.3558974358974
    1500.95
    447.834
    305.87
    364.06
    189.412
    1956.725
    681.88
    end

    However as seen on the graph i attached, each bar represents an income of around £40 a week however i want to increase the width of the bar so that in total each bar represents a higher proportion of income- preferably each bar representing £200. How do i do this?
    Thank you


  • #2
    If you want to graph the distribution of income, see

    Code:
    help hist
    and the options start() and width()

    With graph bar, you will need to create the categories by hand. Here is one approach using your data.

    Code:
    gen category=.
    forval i= 200 (200) 2000{
    local j= `i'-200
    replace category=cond(inrange(p344p, `j', `i'-1), `i', category)
    }
    
    label define category 200 "0 to 199" 400 "200 to 399" 600 "400 to 599" ///
    800 "600 to 799" 1000 "800 to 999" 1200 "1000 to 1199" 1400 "1200 to 1399" ///
    1600 "1400 to 1599" 1800 "1600 to 1799" 2000 "1800 to 1999"
    label values category category
    
    gr hbar (percent) p344p, over(category) bar(1, color(none)) scheme(s1color) ///
    ytitle("Percent") title("Income distribution in the sample")

    Graph:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	33.8 KB
ID:	1496236

    Last edited by Andrew Musau; 02 May 2019, 08:08.

    Comment


    • #3
      Here's another way to bin:

      Code:
      gen category = 200 * floor(whatever/200)
      For more, see e.g. https://journals.sagepub.com/doi/pdf...867X0400300413 (public)

      https://www.stata-journal.com/articl...article=dm0095 (subscription access until 2021)

      Comment

      Working...
      X