Announcement

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

  • Stacked bar chart

    Hi there.

    I am struggeling with creating a stacked bar chart for 12 variables (subject's self-reports on ever having had particular diseases). I matched their selfreports with their real medical history and got three categories for every disease-related : -1 equals those stating don't know , 1: for a correct self-report and 2 for an incorrect self-report
    Thus the data regarding those variables looks like this:

    id | selfreport_dis1 |selfreport_dis2 |selfreport_dis3| selfreport_dis4 .....
    1 | 2 | -1 | 2 | 1
    2 | 1 | 1 | -1 | 2
    3 | 2 | -1 | 2 | 1
    ..

    I would like to present the data in form of numerous stacked bar charts (all showing the percentage of each self-report- category within one bar chart for one disease ); looking similiar to the following picture with one chart for every disease.


    Can somebody help me out here?

    I further would like to distinguish within the three different categories on those which really have had the disease and those which haven't had it yet and maybe differentiate between those groups with two different kinds of patterns (maybe stripes and dots) within one of the three chart's categories.

    I am not quite sure if I was able to state my problem in an understandable way. Let me know if you need other or more detailed information on my data.

    I really appreciate your help and thanks alot.

  • #2
    mo gro your full real name? Please read and act on http://www.statalist.org/forums/help#realnames

    Please also read and act on http://www.statalist.org/forums/help#stata Your data example is helpful but still requires some engineering to get to workable code.

    This may help:

    Code:
    clear 
    
    input id selfreport_dis1 selfreport_dis2 selfreport_dis3 selfreport_dis4 
    1  2  -1  2  1
    2  1  1  -1  2
    3  2  -1  2  1
    end 
    
    reshape long selfreport_, i(id) j(which) string 
    label def report -1 "don't know" 1 incorrect 2 correct 
    label val selfreport_ report 
    
    label var selfreport_ "report" 
    
    graph hbar (count),  over(selfreport_) over(which) asyvars stack ///
    bar(1, color(black*0.5)) bar(2, color(red*.5)) bar(3, color(blue*0.5)) ///
    name(asked, replace) legend(row(1))

    Comment

    Working...
    X