Announcement

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

  • Bar graph trouble

    Click image for larger version

Name:	graph-statalist01.jpg
Views:	1
Size:	345.2 KB
ID:	1478500
    Code:
    graph bar (percent), by(year) over(wbsat) over(white) title(SWB)
    I am trying to make a graph that compares SWB (subjective well-being) between white and non-white people in a balanced panel dataset (0 is non-white 1 is white). It appears the graphs are showing the percent of the whole sample that responds with a 1,2,3..etc for each race, which is why the bars for the white group are all so short. I want each bar to show the fraction of respondents with a given SWB score relative to their own race, but I want them on the same graph. In other words, I want the graph to look like this, but I want the bar for a SWB of 5 in group 1 to show what percentage of white people answered 5. As it stands, that bar shows the percent of the whole sample that answered with 5 and was also white. Sorry for the long-winded explanation this is hard for me to explain in words.

  • #2
    Please note the longstanding request in the FAQ Advice to give a real(istic) example of your data using dataex, or failing that to phrase your question in terms of a dataset all can use. Not doing that is likely to have put off some people who might have replied and certainly delayed my response.

    There are various solutions to your problem, including just calculating what you want to show in advance of the graph command. One fairly easy solution is to install catplot from SSC. This is the essence:

    Code:
    ssc install catplot 
    
    sysuse auto, clear
    catplot rep78 foreign , percent(foreign) recast(bar)
    I used the s1color scheme.

    Click image for larger version

Name:	bar_jan13.png
Views:	1
Size:	25.0 KB
ID:	1478532


    The extension to your problem should be something like

    Code:
     
     catplot wbsat white, by(year) percent(white year) recast(bar) title(SWB)
    although I worry on your behalf about showing 1(1)10 legibly on the axis scale. Also, I don't know why your example graph command is in terms of year but the graph talks about contacts.


    Comment

    Working...
    X