Announcement

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

  • #16
    You're entirely in order here. You are asking clear questions with reproducible code, so you need not apologise for that.

    The small problem is just as you go round the loop

    Code:
    oreach var of varlist rep78 turn {
    qui su `var'
    loc rn "`r(N)'"
    }
    the local macro is overwritten each time and ends with the result for the last variable mentioned. There won't be a separate local macro for each variable..

    Here is a fix:


    Code:
    sysuse auto, clear
    
    foreach var of varlist rep78 turn {
        su `var', meanonly 
        loc n`var' = r(N)
    }
    
    #delimit ;
    graph hbar (mean)rep78 turn,
    asyvars
    showyvars
    yvaroptions(relabel(1 "rep78 (n=`nrep78')" 2 " turn (n=`nturn')")
    gap(*1.5) label(labcolor(black) labsize(small)))
    bar(1, fcolor(gs9))
    blabel(bar, pos(outside) format(%12.1f))
    ysize(3) yla(1(1)5)
    exclude0
    legend(off)
    plotregion(lcolor(none))
    scheme(s1mono)
    title("Some title" " ", size(large) span)
    ytitle(" ""Some ytitle" "", size(small))
    name(rep78_origin_N3 , replace) ;
    graph save rep78_origin_N3, replace;
    #delimit cr

    Comment

    Working...
    X