Announcement

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

  • Question on option "xline" for twoway graphs (plot: line)

    Dear Forum,

    I try to add a vertical line to my illustration [twoway graph (plot: line)]. The x-axis is my time variable from a panel dataset, which was computed in the following way:

    generate yearmo = ym(year, month)
    format yearmo %tm

    I now try to use the xline option to insert a vertical line on the x-axis, but Stata is not accepting any specified date e.g. 2015m3. I assume I am entering the date in a wrong format, but this is how the dates are specified when I look at the dataset. When I enter a random number e.g. 100, Stata accepts the option but I don't see a line.

    Thank you very much in advance for your advice!

    Regards,

    Ross


  • #2
    The monthly date shown as 2015m3 is "really" 662. Your seeing anything else is a consequence of your assigned display format.

    Conversely 100 as a monthly date was in 1968 and is ignored as (presumably) outside the range of your data.

    There are various ways to get what you want.

    Here is a demonstration you can try:

    Code:
    clear
    
    di %tm 100
    di ym(2015, 3)
    di %tm 662
    
    set obs 12
    gen y = 42
    gen date = ym(2015, _n)
    format date %tm
    line y date, xli(`=tm(2015m3)')
    line y date, xli(`=ym(2015,3)')

    Comment


    • #3
      Hi Nick, thank you! Using xline(`=tm(2008m9)') instead of simply 2015m3 worked!

      Comment


      • #4
        Modulo the fact that September 2008 was not March 2015....

        Comment

        Working...
        X