Announcement

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

  • Manipulate x-axis in twoway graph with dates


    Hi Stata users, I want to make a twoway bar graph that plots a number (on the y axis) against a date (on the x axis). I want to manipulate the length, label and ticks of the x-axis. I tried to enter the dates in different formats into the xscale and the xlabel options, but keep getting a "range() invalid - invalid numlist" error for xscale and a "invalid label specifier" error for xlabel. How do I refer to dates in xscale and xlabel? I tried entering the dates in different formats.

    Code:
    input date number  16743 116
     16835 384
     17034 152
     17113 267
     17191 939
     17246 372
     17265 443
     17302 406  
    17498 210  
    end
    format date %tdnn/dd/CCYY
    
      twoway bar number date , xscale(range(11/3/2005 (100) 11/28/2007))  xlabel(11/3/2005 1/25/2007 11/28/2007)
    I also tried things like:
    Code:
     twoway bar number date ,  xlabel(mdy(11,3,2005) mdy(1,25,2007)   mdy(11,28,2007) , format(%tdnn/dd/CCYY))

    None of these worked. I appreciate any advice. Thank you!

  • #2
    Cross-posted on Stack Overflow and answered. Please note our cross-posting policy, which is that you tell us about it.

    Comment


    • #3
      Work backwards from the date that you want to display.

      Code:
      . di  %tdnn/dd/CCYY 16743
       11/3/2005
      
      . di  %tdnn/dd/CCYY 17191
       1/25/2007
      
      . di  %tdnn/dd/CCYY 17864
      11/28/2008
      For example, if 28th Nov. 2008= 17864, one unit represents a day, so 8th Nov. 2008 = 17864-20= 17844.

      Code:
      twoway bar number date ,  xlabel(16743 17191 17864)

      Comment


      • #4
        Answered on Stackoverflow: https://stackoverflow.com/questions/...24787_56094074
        Thanks Nick for pointing out the policy. Thanks Andrew for the suggestions.

        Comment

        Working...
        X