Announcement

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

  • Stacked bar chart for panel data

    Hi Statalist

    My question is about creating a stacked bar chart for panel data. To illustrate:

    Code:
    . webuse citytemp
    
    ## the rest of the code is to create a made-up panel data
    . generate id = _n
    . generate year = 2000
    . expand 4
    . bysort id: replace year = year + _n
    From this I want to see the changing composition of, say, the various regions over time (it doesn't change in this made-up example but in my actual dataset there are differences over time).

    Code:
    . tabulate region year, column nofreq
    
        Census |                    year
        Region |      2001       2002       2003       2004 |     Total
    -----------+--------------------------------------------+----------
            NE |     17.36      17.36      17.36      17.36 |     17.36
       N Cntrl |     29.71      29.71      29.71      29.71 |     29.71
         South |     26.15      26.15      26.15      26.15 |     26.15
          West |     26.78      26.78      26.78      26.78 |     26.78
    -----------+--------------------------------------------+----------
         Total |    100.00     100.00     100.00     100.00 |    100.00
    Question: What I would like to do is to graph the above two-way tabulation table like the following using Stata.

    The code I tried so far is
    Code:
    . graph hbar region, over(year) stack percent
    which doesn't work. Any suggestions would be greatly appreciated.

    Thanks
    Attached Files

  • #2
    The -catplot- command seems to have done the trick.

    Code:
    . catplot region, over(year) stack percent asyvars
    But if anyone can suggest a way to replicate this graph using the official Stata commands, that would be great.

    Comment

    Working...
    X