Announcement

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

  • Plotting time series date labels in French (or another language format)

    I'd posted this question on the old statalist some time ago with no bites (http://www.stata.com/statalist/archi.../msg00937.html) and since found from Stata that there is no internal language option that allows month names other than English for labels. While I could change the labels manually in the graph editor, it's not practical because I have a fairly large number of graphs to plot in both French and English and I redo this set pretty much daily.

    Having a bit of time to think about it, Nick Cox's -labmask- ado came to the rescue. The only caveat is that plotting as a time series, you need to add have all dates available in the period you wish to plot and a few extra at the end to accommodate any labels that are greater than your maximum plotted value. If you don't, you may end up with a date in the plot that isn't labelled in the way you'd like.

    This solution works very well for my needs so thanks to Nick for this helpful ado. If you had to do more than 2 languages, you'd just need to generate the label and the source variable to use as the label source for -labmask- and re-use -labmask- prior to the graphing command for that language.

    Code:
    * Requires labmask by Nick Cox
    graph drop _all
    sysuse xtline1, clear
    ren day date
    
    local new = _N + 10        /* Adds a few variables to facilitate plotting the last date label */
    set obs `new'
    replace date=date[_n-1]+1 if missing(date)
    tsset person date
    tsfill  /* If there are missing date values between the min and max date in your dataset */
    
    * Define French language month labels
    local french_mon janv. f`=char(233)'vr. mars avr. mai juin juil. ao`=char(251)'t sept. oct. nov. d`=char(233)'c.
    loc i=1
    foreach month of loc french_mon{
    label def frmonth `i' "`month'", modify
    loc i=`i'+1
    }
    
    * New variables
    gen day=day(date)
    tostring day, replace
    gen month=month(date)
    
    * French
    lab val month frmonth
    decode month, gen(frmonth)
    egen frlab=concat(day frmonth)
    
    * Set xlab to give you the desired label scales given your graph type
    
    labmask date, values(frlab)
    tsline calories, by(person)  tlab(#8, format(%tdmd)) name(english_ver) /* English */
    tsline calories, by(person) tlab(#8,valuelabels) name(french_ver) /* French */
    
    exit

  • #2
    Thanks for the mention. The best discussion of labmask is at http://www.stata-journal.com/article...article=gr0034. It may be downloaded from the Stata Journal site after running

    Code:
     
    search labmask, sj

    Comment

    Working...
    X