Align bars in ciplot

588 Views Asked by At

I'm working with the ciplot graphing module for Stata and am encountering a problem with the alignment of bars when I use the by() option. Here's a trivial example demonstrating the issue:

webuse citytemp, clear
ciplot heatdd cooldd, by(region) horizontal recast(conn)

ciplot

So, the graph shows means and confidence intervals for two variables across categories of the region variable. The bars for the different variables do not align horizontally, though. For each region, the point and bar for heatdd is one line above, and the point and bar for cooldd is one line below, the category label. I would like these to be on the same line, but I can't figure out how to achieve it.

I'm open to solutions that do not involve ciplot, but I have found it to be useful for the specific task I'm working on.

1

There are 1 best solutions below

3
On BEST ANSWER

This is my program (in Stata terms, downloadable via ssc install ciplot) so I can speak confidently. (On Statalist, it's expected that you explain the exact provenance of user-written programs; that would be good practice here too.)

It's not a bug; it's a feature (supposedly).

The offsets are entirely deliberate, to avoid messes when two or more intervals would just overlap and occlude each other, which is entirely likely when groups or comparable variables have similar values, which in turn is common when you do this. Even in your example, intervals for heating and cooling degree-days for the South would overlap otherwise, so the graph makes the point for me.

I can see that it's not what you want, but

  1. There is no option in ciplot to remove the offset. I can see a case for one, but

  2. My advice is now to use statsby to get a reduced dataset containing the confidence interval information, and then the graphics are typically a couple of command lines and you get to choose what you want. This approach is documented in a paper easily accessible from the Stata Journal.

You are always welcome to clone the program and modify the code using a different program name, with notional mention of the original.