Announcement

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

  • 100% stacked bar chart from marginsplot after ologit

    I have a simple ologit model. Outcome y has four ordered categories: 1 2 3 4. Predictor X is a binary variable. Is there a way to use marginsplot to create a 100% stacked bar chart of the predicted probabilities of each category?

    See example below:


    Click image for larger version

Name:	Rplot01.png
Views:	1
Size:	24.0 KB
ID:	1769499


    Thanks!

  • #2
    The problem with a stacked bar chart is that you can easily compare the years for the lowest and highest categories. However, for the two middle categories it easily becomes very hard to see what is going on. That is not a good characteristic of a graph. Instead I would use Nick Cox's tabplot instead, see search tabplot . Here is an example:


    Code:
    // estimate an ordered logit
    clear all
    webuse nhanes2f
    svyset psuid [pw=finalwgt], strata(stratid)
    svy: ologit health female black age c.age#c.age
    
    // get the margins, and store the result in
    // the temporary file `tmp'
    tempfile tmp
    margins , at(female=1 black=(0 1) age=40) saving(`tmp')
    
    // open the margins result in a new frame
    frame create tograph
    frame change tograph
    use `tmp'
    
    // fix some labels
    label define _predict  1 "Poor"     ///
                           2 "Fair"     ///
                           3 "Average"  ///
                           4 "Good"     ///
                           5 "Excellent", modify
    label var _predict "self-rated health"        
    
    // make the graph               
    tabplot _predict _at2 [iw=_margin],        ///
        xtitle("") yreverse                    ///
        showval(format(%3.2f))                 ///
        subtitle(predicted probability)                       
    
    // Go back to the original data
    frame change default
    frame drop tograph
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.9 KB
ID:	1769515
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks! I've never seen a graph like that but i'm excited to give it a try. I agree that the original graph is hard to tell the changes, especially in the middle categories. Maybe a middle ground is printing the percentage of the category within each block.

      Comment


      • #4
        Originally posted by Erik Reinbergs View Post
        I agree that the original graph is hard to tell the changes, especially in the middle categories. Maybe a middle ground is printing the percentage of the category within each block.
        But what is the added value of that graph than? Isn't a table clearer than a confusing graph propped up by the values from that table?
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment

        Working...
        X