Announcement

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

  • using labmask in tsline

    hello everyone

    Somehow I could not get the desired results when using labmask in the following situation. I want to produce a graph with a formatted date axis (code 1 below). In my data my time variable is not directly the date variable but group of dates (to take out the gaps between some dates). Just wondering if there is a way to show a formatted date axis with the grouped date variable. I tried with code 2 below with no success. Grateful for any help.

    Code:
    *CODE 1
    clear 
    set obs 10
    gen date=20000+_n*2 //dates with gaps
    
    gen x=_n
    
    tsset date
    tsline x , tlabel(, format(%dm-CY))
    
    *************
    *CODE 2
    clear 
    set obs 10
    gen date=20000+_n*2 //dates with gaps
    egen day=group(date)
    
    gen x=_n
    
    tsset day
    g sdate=string(date,"%dm-CY")
    labmask day, values(sdate)
    
    tsline x

  • #2
    labmask is from the Stata Journal, as you are asked to explain.

    Code:
    . search labmask, sj
    
    Search of official help files, FAQs, Examples, SJs, and STBs
    
    SJ-8-2  gr0034  . . . . . . . . . .  Speaking Stata: Between tables and graphs
            (help labmask, seqvar if installed) . . . . . . . . . . . .  N. J. Cox
            Q2/08   SJ 8(2):269--289
            outlines techniques for producing table-like graphs
    I think your problem is with tsline which will respect an assigned display format, but doesn't by default look for value labels. Try further

    Code:
    tsline x, xla(, valuelabel)
    tsline x, xla(1(2)9, valuelabel)

    Comment


    • #3
      Thank you for the help, Nick!

      Comment


      • #4
        Nick Cox
        On my x-axis, I have the dates in format like DaymonthYear. When I use -tsline-, I want to plot only year. I've created a variable 'year' and applied the following code:
        labmask(date), values(year)
        tsline var, xlabel(,valuelabel).

        But the results are quite surprising: the first date is in format like 03jan2000, the other is OK (year 2002), followed by other variable like 03jan2004 and again by the year (2006), and so on. Thank you.

        Comment


        • #5
          Friedrich Mises You don't give a reproducible data example that I or anyone else can play with. But this doesn't seem puzzling to me.

          With tsline and no values specified you are relying on its defaultchoice of axis label positions. You will get value labels shown if and only if value labels are defined for the values chosen by tsline; if a value has no value label defined the display format you chose will come into effect.

          If you run this code, you will see the principle exemplified.

          Code:
          clear
          set obs 2 
          gen date = cond(_n == 1, mdy(1,1,1998), mdy(1,1,2000))
          gen year = year(date) 
          format date %td
          labmask date, values(year) 
          gen y = 42
          tsset date 
          tsline y , xla(, valuelabels)
          A more direct solution for what you want is likely to be

          Code:
          tsline var, xlabel(, format(%tdCCYY)) 
          but odd results are quite possible unless your axis labels are an exact number of years apart.

          Comment


          • #6
            Nick Cox, thank you very much, the last code worked just fine.

            Comment

            Working...
            X