Announcement

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

  • Overlaying Vertical Lines on "twoway bar" Graph

    Hello all,

    I'm having an issue creating twoway bar graphs with an overlaid vertical line. I tried using the "tline" command - which does add a vertical line - but that line appears below the bar chart data. I would like the vertical line at 2009m9 to "overlay" (not sure if that's the correct terminology) the bar chart.

    The datem variable takes the form 2000m1, 2000m2, 2000m3, etc.

    Code:
    *Create monthly graphs for all 50 taxes
    forvalues j=1/50 {
        local i : display %02.0f `j'
        sort datem
        twoway (bar tax_`i' datem), tline(2009m9, lc(red))
        graph export "$folder\\monthly_tax_`i'_Revenue.tif",replace
        }
    Thanks in advance for the help.
    -Chris
    Last edited by Chris Matix; 23 Sep 2014, 13:55.

  • #2
    Reference lines like that you asked for are deliberately laid down first in order not to occlude displays of the data. But you can subvert that.

    You just need to draw one or more lines on top e.g. with twoway pci: see http://www.stata.com/statalist/archi.../msg00702.html

    Comment


    • #3
      Thanks, Nick. Because the scale of revenues for each tax varies, I'm having trouble setting the y-value bounds for the pci command. I've tried the following, but Stata returns an error message of:

      "option ( not allowed"

      Code:
      *Create monthly graphs for all 50 taxes
      forvalues j=1/50 {
          local i : display %02.0f `j'
          sort datem
          twoway (bar tax_`i' datem), (pci `r(min)' 2009m9 `r(max)' 2009m9)
          graph export "$folder\\\monthly_tax_`i'_revenue.tif",replace
          }
      Last edited by Chris Matix; 23 Sep 2014, 14:24.

      Comment


      • #4
        Several problems here.

        1. Where do r(min) and r(max) come from? For that you need a prior summarize, which you need to insert before each graph command.

        2. I see no reason to believe that pci will understand 2009m9. It's not a graph command with special intelligence for time series.

        3. The pci call is a separate command, not a graph option.

        On a different note: using forward slashes for filepath separators is allowed even under MS Windows.

        This code should get you closer. You can take repeated calculations out of the loop.

        Code:
          
        sort datem  
        local mydate = ym(2009, 9)  
        forvalues j=1/50 {    
            local i : display %02.0f `j'    
            su tax_`i', meanonly      
            twoway bar tax_`i' datem || pci `r(min)' `mydate' `r(max)' `mydate'      
            graph export "$folder/monthly_tax_`i'_revenue.tif", replace
        }
        Last edited by Nick Cox; 23 Sep 2014, 16:52.

        Comment


        • #5
          Hi Nick, Thanks for the help with the code. Just wanted to confirm that your fix works. I appreciate your time and help.
          -Chris

          Comment

          Working...
          X