Announcement

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

  • Using variable notes as captions in graphs

    Dear all,

    I need to create multiple graphs based on different variables. To do so, I have created a loop, where the title of the graph is taken from the variable label. I am wondering if there is any way to do something similar but with notes and captions. That is, to take variable notes and use them to add a caption in the graph. Not all my variables have notes, but some of them do. Here is the code:

    Code:
    foreach i of varlist ncittop100_1_t_rel - ppcittop200_10_t_rel {
    
    local label: variable label `i'
    
    twoway (tsline `i'_idex1_ if !missing(idex1) & time>=-5, lcolor(red) lwidth(medthick) lpattern(solid) connect(direct))/*
    */        (tsline `i'_idex2_ if !missing(idex2) & time>=-5, lcolor(blue) lwidth(medthick) lpattern(solid) connect(direct)),/*
    */        ytitle(difference within reference group) scheme(s1manual) legend(off) tline(-0.5, lpattern(dash) lcolor(gs6)) tline(0.5, lpattern(dash) lcolor(gs6)) /*
    */        legend (on order(1 "All " 2 "Sample") cols(1) all size(med)) /*
    */        yline(0, lwidth(vthin) lpattern(dash) lcolor(gs12)) /*
    */        title("`label'", span) /*
    */        caption("---------", size(small))
            
    graph export `i'_.eps, as(eps) preview(off) or(portrait) mag(200) replace
    }
    So, the idea would be to fill the "caption" space with the notes taken from each variable in varlist.

    Many thanks in advance.

  • #2
    You can do this with notes _fetch.
    Code:
    help notes_
    The example below shows how to extract notes attached to variables.
    Code:
    sysuse auto, clear
    notes mpg: mpg = miles per gallon
    notes weight: lbs = pounds
    notes _fetch mpgnote : mpg 1
    notes _fetch weightnote : weight 1
    local caption "`mpgnote'. `weightnote'."
    scatter mpg weight, caption("`caption'")

    Comment


    • #3
      Excellent! Worked perfectly.

      Thanks a lot.

      Comment

      Working...
      X