Announcement

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

  • Overlaying (nested) histograms

    Dear Statalists,

    This may be a rather simple request but I have not managed so far.

    I have one categorical variable with three values (let's call it outsider_status). I have then another variable (political parties) which is nested in a third variable (countries).

    I would like to have a histogram plot of the percentage of the outsider_status variable for each political party compared with the country average. In other words, I would like to see what the percentage of outsider_status for each party is in comparison to the country average. It may be the case that there's more than one party from the same country, in which case the country average should remain the same, whereas the party levels would change.

    Could anyone point me in the right direction?

    Many thanks.
    Best regards,
    Guillem

  • #2
    I'm not sure a histogram is appropriate for a variable with only three values, but perhaps I misunderstood. Maybe something like this example? Among other things, you probably would want to set a common yscale and xscale and customize the legend.

    Code:
    sysuse citytemp
    
    forvalues i = 1/3 {
        twoway (histogram tempjan if division==1, fcolor(red%50) lcolor(red%50) ///
           name(graph`i', replace) percent title("`: lab (division) `i''")) ///
           (histogram tempjan, fcolor(%50) lcolor(%50) percent)
        }
    David Radwin
    Senior Researcher, California Competes
    californiacompetes.org
    Pronouns: He/Him

    Comment

    Working...
    X