Announcement

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

  • xtgraph cannot modify legend

    Hello,

    I am using the user-written command
    HTML Code:
    xtgraph
    .

    The following command illustrates is the simple graph I am creating

    HTML Code:
    xtgraph lwage, av(mean) bar(ci) 
    However, it seems I cannot modify the legend. I tried both of these legend options with no result:

    HTML Code:
    xtgraph lwage, av(mean) bar(ci)  legend(pos(6) row(1) order(1 "Yearly Means of log(wage)" 2 "CIs" ))
    HTML Code:
    xtgraph lwage, av(mean) bar(ci) legend(pos(6) row(1) label(1 "Yearly Means of log(wage)") label(2 "CIs"))
    Can someone help me please? Thank you!

  • #2
    Please follow FAQ Advice #12 in explaining where community-contributed commands you refer to come from and in giving a reproducible example.

    xtgraph is from SSC and shows its age a little insofar as some of the explanation of the syntax applies only if you are asking for version 7 syntax, which you aren't.

    This part of the help is what is needed to get what you want:

    Control of version 8+ graphics is available through the options lineopts , bartype,
    and baropts. Any graphics options contained in lineopts() is used as an option
    or set of options for the line portion of the graph drawing. See @graph twoway
    line). Similarly, graphics options for the bars are given by baropts. See graph twoway bar@
    Tweaks of the legend should work if bundled within baropts() or lineopts().

    I got this to work in Stata 19.50

    Code:
    webuse grunfeld
    gen ln_invest = ln(invest)
    xtgraph ln_invest, av(mean) bar(ci) baropts(legend(pos(6) row(1) label(1 "Yearly means of log invest") label(2 "CIs") )))
    I couldn't get the essentially equivalent call using legend(order()) to work, but didn't try to work out why not.

    I was curious about getting essentially the same graph using cisets from SSC, as discussed at https://www.statalist.org/forums/for...-interval-sets

    This is a start, after which all standard options about legends should apply.

    Code:
    cisets mean ln_invest, over(year) saving(results) 
    use results, clear
    twoway connected point origgvar || rcap ub lb origgvar
    xtgraph offers a great deal that cisets doesn't try to produce.

    Neither command offers any functionality to address the dependence structure you might expect with panel data, whereas xtgraph is focused on precisely that kind of data.

    Comment


    • #3
      Thank you very much! It worked.

      Comment

      Working...
      X