Announcement

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

  • Stacked Bar Chart If Condition

    Hi,

    I've run into a problem and I'm not sure how to fix it. I would like to include an if statement for a barchart I am producing. The data I have is in the form count type year, where count is the number of units for the type in the year.

    Code:
    egen count_total_by_y_t = total(count), by(year type)
    gen count_total_by_y_t_k = count_total_by_y_e/1000
    graph bar count_total_by_y_t_k, percentages over(engine) asyvars over(year) stack
    This code produces the chart I would like. However I would like to limit it to a select few types. Type is categorical and ranges from 1-8. How should I change the code so that the bar chart contains only types 2 to 5 for example?

    Thanks

  • #2
    if inlist(type, 2, 3, 4, 5) or if inrange(type, 2, 5) is the usual kind of restriction. You don't usually need to calculate percents, as graph bar will do that for you.

    Comment

    Working...
    X