Announcement

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

  • Labeling Scatter plot in twoway

    Dear all,

    I have a problem labeling plot using twoway command.

    I am plotting scatter with line of best fit together where I use the twoway command. However, I cannot label the plots by bench.

    This is my raw data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str5 bench float(StateWins shrinesper1000)
    "abohc"  .4228856           0
    "banhc"  .5753425  .013336194
    "dikhc" .51754385   .00256476
    "hydhc"  .5224359  .010040317
    "islhc"  .3741007           0
    "karhc"  .4391026  .003207205
    "kashc"      .368  .010207728
    "khyhc"  .6451613           0
    "larhc"  .4615385  .007298633
    "lhrhc"  .4746988           0
    "mulhc"  .3854749  .003135484
    "phc"    .4971098 .0018573207
    "quehc"   .426087           0
    "rwphc"   .462069 .0011151128
    "sibhc"  .4277108  .005543299
    "sukhc"  .6610879   .01560029
    end
    I try the following code

    Code:
    twoway (scatter StateWins shrinesper1000) (lfit StateWins shrinesper1000), mlabel(bench)
    When I try this, I get the error "option mlabel() not allowed".

    Now I know, that I can obtain labelled scatter plot through:

    Code:
     scatter StateWins shrinesper1000, mlabe l(bench)
    However, I need the diagram along with line of best fit. Is it possible to obtain both labelled scatter with the line of best fit?

    Help in this regard will be really appreciated. Thank you!!

  • #2
    put the ", label(bench)" as an option to your first graph (the scatter plot) as in
    Code:
     
     twoway (scatter StateWins shrinesper1000, mlabel(bench)) (lfit StateWins shrinesper1000)

    Comment


    • #3
      Thank you!!!

      Comment

      Working...
      X