Naji Nassar (MIReS) wrote:
> Hi all
>
>
> I'm trying to change the legend of my graph (3 lines, and a by option)
> twoway (line Ratiopen PdfMag if (Rarete==0 & Report == 1 & (PdfBrd < 0.06 &
> PdfBrd > 0.04) & HetMag == 20) ,ylabel(0(0.25)1)) (line Ratiopen PdfMag if
> (Rarete==0 & Report == 1 & (PdfBrd < 0.06 & PdfBrd > 0.04) & HetMag == 50)
> ,ylabel(0(0.25)1)) (line Ratiopen PdfMag if (Rarete==0 & Report == 1 &
> (PdfBrd < 0.06 & PdfBrd > 0.04) & HetMag == 80) ,ylabel(0(0.25)1)),
> by(HetBrd, legend( 1 "Weak" 2 "Medium" 3 "Strong" ) note("") title(No
> Report) iyaxes ixaxes) ytitle("Penetration rate") note("") xtitle("Share of
> preferences" "Brand heterogeneity") xsize(4) ysize(4)
>
> I'm still havin 'Ratiopen' at the legend (3 times). I'd like to avoid
> retructuring the data (3 variables rather than overlaying 3 graphs)
>
> Note that PDfBrd==0.05 gave 'no observation' while it's the only value
> between 0.04 & 0.06)
In your command the legend option is part of by() but should be put outside
by(). For a reason, which I do not understand, legend-options which changes
the contents of the legend has to be placed outside of by(), while options
which changes the position of the legend has to be placed inside by().
Moreover note, that your legend-option reads
legend( 1 "Weak" 2 "Medium" 3 "Strong" )
This should be changed to
legend(label(1 "Weak") label(2 "Medium") label(3 "Strong")
Hence, your command should look like
. twoway (line Ratiopen PdfMag if ... , ylabel(0(0.25)1))
(line Ratiopen PdfMag if ... , ylabel(0(0.25)1))
(line Ratiopen PdfMag if ... , ylabel(0(0.25)1))
, by(HetBrd
note("") title(No Report) iyaxes ixaxes
)
legend(label(1 "Weak") label(2 "Medium") label(3 "Strong")
ytitle("Penetration rate") note("")
xtitle("Share of preferences" "Brand heterogeneity"
xsize(4) ysize(4)
BTW, it took me just a minute to trace that down with help of Mitchell's new
book "A Visiual Guide to Stata Graphics". I don't think that I would have
succeeded that fast with the online-help or the manuals. So two thumbs up for
Mitchell's book here!
Probably a note to StataCorp: It might be helpful if there were a sort of
short notation of ignored options in commands like
. line weight length, by(foreign, legend(1 "a" 2 "c"))
many regards
uli
--
[email protected]
+49 (030) 25491-361
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/