Announcement

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

  • Help with Catplot

    Hello everyone, can someone please help me.

    I am trying to make a graph in which I can visualize the differences in healthy and unhealthy status (percentages that added together are 100% in the row) according to ethnicity (indigenous vs non-indigenous) in four age groups (60, 70, 80 and 90+ years).
    But, I try and the truth is that it comes out anything but what I require. Clearly, I don't know how to use the catplot command. Can anyone guide me and/or point out if it is possible to do what I want?

    Regards






    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(race age) double(healthy unhealthy)
    1 1 49.6 50.4
    1 2 39.4 60.6
    1 3 15.9 84.1
    1 4  8.3 91.7
    2 1 53.3 46.7
    2 2 46.2 53.8
    2 3 37.1 62.9
    2 4   25   75
    end
    label values race rac
    label def rac 1 "Indigenous", modify
    label def rac 2 "Non-Indigenous", modify
    label values age ag
    label def ag 1 "60 yeras", modify
    label def ag 2 "70 years", modify
    label def ag 3 "80 years", modify
    label def ag 4 "90+ yeras", modify
    ------------------ copy up to and including the previous line ------------------












  • #2
    There are many variations, noting last of all that % healthy + % unhealthy are just complements. Here I show results from tabplot (Stata Journal) as well as from catplot (SSC). I have corrected yeras to years.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(race age) double(healthy unhealthy)
    1 1 49.6 50.4
    1 2 39.4 60.6
    1 3 15.9 84.1
    1 4  8.3 91.7
    2 1 53.3 46.7
    2 2 46.2 53.8
    2 3 37.1 62.9
    2 4   25   75
    end
    label values race rac
    label def rac 1 "Indigenous", modify
    label def rac 2 "Non-Indigenous", modify
    label values age ag
    label def ag 1 "60 years", modify
    label def ag 2 "70 years", modify
    label def ag 3 "80 years", modify
    label def ag 4 "90+ years", modify
    
    capture frame drop graphsandbox 
    
    frame put *, into(graphsandbox) 
    
    frame graphsandbox { 
        rename (*healthy) (percent=) 
        reshape long percent, i(race age) j(state) string 
        
        catplot state age [aw=percent],  asyvars blabel(bar, format(%2.1f)) over(race)  percent(race age) name(G1, replace)
                
        tabplot age state [iw=percent], xsc(r(0.8 .)) xtitle("") horizontal showval(format(%2.1f)) separate(state) bar1(color(stc1)) bar2(color(stc2)) by(race, note("")) name(G2, replace)
    }
    
    graph hbar (asis) healthy, over(race) over(age) name(G3, replace) ytitle(% healthy) blabel(bar, format(%2.1f))

    Click image for larger version

Name:	sandoval1.png
Views:	1
Size:	47.5 KB
ID:	1715554
    Click image for larger version

Name:	sandoval2.png
Views:	1
Size:	37.1 KB
ID:	1715555
    Attached Files

    Comment


    • #3
      Dear Nick

      Many thanks for your help.


      Moses

      Comment

      Working...
      X