Announcement

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

  • Modify monthly scale on x axis

    I need to modify the x-axis of this line plot so that the first value on the axis is 1928m1 and the last one is 1933m12, with a proper amount of intermediate values.

    Click image for larger version

Name:	Cattura.PNG
Views:	1
Size:	39.0 KB
ID:	1444775



    I tried using the Graph Editor menu from the Graph window but I cannot insert letters in the boxes (e.g. values as 1928m1). Then I tried to use the values I got immediately after the ym function, which are, respectively for 1928m1 and 1933m12, -384 and -313. But now the problem is that I do not know which Delta value to insert because I can't compute the distance in time using this format.

    Click image for larger version

Name:	Cattura2.PNG
Views:	1
Size:	17.9 KB
ID:	1444776


    Does anybody have a suggestion? Ty

  • #2
    There are several ways to do this. Here's one I like. Using display as a calculator shows that the limits you want are -384 and -313. So use those values in an xsc(r()) option.

    That's not the quickest or slickest way to do it, but it connects with what Stata sees at data level.

    Code:
    . di ym(1928, 1)
    -384
    
    . di ym(1933, 12)
    -313

    Comment


    • #3

      Thanks Nick.

      So the idea would be to run something like graph
      Code:
       twoway line typhus date, xsc(range(-384, -313)
      ?

      In any case, how could I add other intermediate values on the axis?

      Comment


      • #4
        You'd need an extra parenthesis. I wouldn't plot the graph as in #1. I would put years (only) in the middle of each year and ticks only at the end of each year.

        Here's some technique:

        Code:
        clear 
        set obs 72 
        gen mdate = ym(1927, 12) + _n 
        set seed 2803
        set scheme s1color
        gen whatever = runiform()
        
        line whatever mdate, xla(`=ym(1928, 6) + 0.5'(12)`=ym(1933, 6) + 0.5', format(%tmCY) noticks) ///
        xtic(`=ym(1927, 12)+0.5'(12)`=ym(1933, 12)+0.5', tlength(*3)) xtitle("")

        Click image for larger version

Name:	nicedate.png
Views:	1
Size:	75.0 KB
ID:	1444786

        Comment


        • #5
          Thank you for your kind suggestion. Then to move the ticks, I would have to modify the option xtic, right?

          Comment


          • #6
            Indeed. If you want them in a different place, you need to say where that is. I am interested to know where would be a better place.

            Comment

            Working...
            X