Announcement

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

  • Bar charts

    Good morning stata users
    I need assistance please.

    I am working on longitudinal data. I have a variable measured at 7 different time points and have categorized all 7 variables as "<50", "50 -1000" and ">1000" . So i am trying to compute stacked bar graphs containing all 7 variables in one graph. The x axis would be each of the 7 categories at each time point and on the y axis the proportion of the people in each of the categories.


    Thanks

  • #2
    There is some inconsistency here.

    a variable measured at 7 different time points

    7 variables categorised as "<50", "50 -1000" and ">1000"

    7 categories at each time point


    A Stata variable is in other terms a column or field in your data set.

    I am reading this as meaning really

    one variable with 3 categories

    one time variable with 7 distinct values


    In the absence of a data example (FAQ Advice #12) here I use the Grunfeld data bundled with Stata to show some technique. I bin invest into three categories; you already have the analogue.

    catplot is from SSC.

    Code:
    webuse grunfeld, clear 
    
    gen invest_bin = cond(invest < 50, 1, cond(invest < 500, 2, 3)) if invest < . 
    label def bin 1 "< 50" 2 "500 - <500" 3 "{&ge} 500"
    label val invest_bin bin 
    
    catplot invest_bin year if year < 1942, legend(pos(6) row(1)) ysc(alt) percent(year) asyvars stack
    Click image for larger version

Name:	kanyo.png
Views:	1
Size:	23.0 KB
ID:	1723917

    Comment

    Working...
    X