Announcement

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

  • Graph Legend Syntax Question

    Hello,
    I am trying to label my legend in a graph and going crazy trying to figure out what to do. After googling for about an hour and typing and retyping I am getting the same error. I am hoping a fresh set of eyes can help me...
    All I am trying to do is rename the legend to match my variables (which I feel like it should do automatically). Right now it just says "fitted values" for all three lines.

    . twoway (lfit PRICE WINDEX) (lfit PRICE WLINDEX) (lfit PRICE WPINDEX)( legend(lab(1 "WINDEX")(2 "WLINDEX" ) (3"WPINDEX"))))
    ) required
    r(100);



  • #2
    I use extra spaces so you can see the options and parentheses clearly (they do no harm, but are not necessary).
    Code:
    sysuse auto, clear
    twoway (lfit price trunk) (lfit price turn, legend(  label(1 "Trunk")label( 2 "Turn") )   )
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Nevermind. Thanks anyway...

      Comment


      • #4
        Originally posted by Carole J. Wilson View Post
        I use extra spaces so you can see the options and parentheses clearly (they do no harm, but are not necessary).
        Code:
        sysuse auto, clear
        twoway (lfit price trunk) (lfit price turn, legend( label(1 "Trunk")label( 2 "Turn") ) )

        Just saw your reply. Thanks so much. I actually figured it out via the point and click method. Can y ou tell me for the future what was wrong with my code? I am seeing it all over the place as the way to change colors, not sure why mine didn't wrok.

        Comment


        • #5
          You can add options in a separate parentheses, as though there was an empty graph command, but there needs to be a comma before those options.

          Yours code would work with the following modifications

          Code:
          **original**    
          ( legend(lab(1 "WINDEX")(2 "WLINDEX" ) (3"WPINDEX"))))
          
          **revised**    
          ( , legend(lab(1 "WINDEX") lab(2 "WLINDEX" ) lab(3"WPINDEX")  ) )  
          
          *add a comma before legend
          *add lab before each label group
          *take away one close parens at the end
          Stata/MP 14.1 (64-bit x86-64)
          Revision 19 May 2016
          Win 8.1

          Comment


          • #6
            I always use the order() suboption in these circumstances

            Code:
            legend(order(1 "WINDEX" 2 "WLINDEX" 3"WPINDEX"))
            as cleaner.

            Comment

            Working...
            X