Announcement

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

  • Clustered bar chart of probabilities over time (when means already calculated)

    I'd like to represent the following table of probabilities in a chart. Trans is my time variable and I would like the a cluster of the 4 other variables per time point. I tried the following but didn't get what I needed:

    graph bar (asis) stayedNE becameNE becameE stayedE, over(transition_t)

    I'd be very grateful for any help!



    +----------------------------------------------------+
    | transi~t stayedNE becameNE becameE stayedE |
    |----------------------------------------------------|
    1. | 1 to 3 0.771 0.229 0.240 0.760 |
    2. | 3 to 5 0.881 0.119 0.450 0.550 |
    3. | 5 to 8 0.800 0.200 0.256 0.744 |
    4. | 8 to 11 0.862 0.138 0.321 0.679 |
    5. | 11 to 16 0.879 0.121 0.459 0.541 |
    +----------------------------------------------------+

  • #2
    Various problems here. First, please read the FAQ Advice #12 for how to present data examples. This one needs major surgery to make it sensible and usable. http://www.statalist.org/forums/help#stata

    Second, you say that the graph is not as you wish but don't explain why.

    Third, the data structure here is not suitable for graphics.

    I notice just that probability stayed + probability became = 1 so that is the pivot for any graph design.

    Much messing around yielded this:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(transition_t stayedNE becameNE becameE stayedE)
    1 .771 .229  .24  .76
    2 .881 .119  .45  .55
    3   .8   .2 .256 .744
    4 .862 .138 .321 .679
    5 .879 .121 .459 .541
    end
    label values transition_t id
    label def id 1 "1 to 3", modify
    label def id 2 "3 to 5", modify
    label def id 3 "5 to 8", modify
    label def id 4 "8 to 11", modify
    label def id 5 "11 to 16", modify
    
    rename (stayedNE becameNE) (probNEstayed probNEbecame)
    rename (stayedE becameE) (probEstayed probEbecame)
    reshape long probNE probE, i(transition_t) j(which) string
    reshape long prob, i(transition_t which) j(region) string
    graph hbar (asis) prob, over(which) over(transition_t) over(region) stack
    Click image for larger version

Name:	stayedbecame.png
Views:	1
Size:	9.8 KB
ID:	1361026


    Last edited by Nick Cox; 20 Oct 2016, 10:01.

    Comment


    • #3
      Oh wow! This is much much better than I had anticipated. It represents my data beautifully. Thank you so much Nick!

      Comment

      Working...
      X