# st: AW: AW: changing the legend in twoway function

 From "Martin Weiss" To Subject st: AW: AW: changing the legend in twoway function Date Mon, 10 Aug 2009 13:29:31 +0200

```<>

Do the same trick to the -legend()- then:

*************
clear*

inp byte(a   b   c)
1   3   4
2   5   8
end

program define polysameplot

loc j 0

foreach i of numlist `0' {
loc ++j
local gr /*
*/ "`gr' function y=a[`i']+b[`i']*x+c[`i']*x^2, range(-5 5) ||"
local leg /*
*/ `"`leg' `j' "a=`=a[`i']', b=`=b[`i']', c=`=c[`i']'""'
}

tw `gr', legend(on order(`leg'))

end

polysameplot 1 2
*************

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Montag, 10. August 2009 11:17
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: changing the legend in twoway function

<>

Why not accumulate the thing for a -note- to the graph. Gives you more
degrees of freedom re design...

*************
clear*

inp byte(a   b   c)
1   3   4
2   5   8
end

program define polysameplot

foreach i of numlist `0' {
local gr /*
*/ "`gr' function y=a[`i']+b[`i']*x+c[`i']*x^2, range(-5 5) ||"
local note /*
*/ "`note' "a=`=a[`i']', b=`=b[`i']', c=`=c[`i']'""
}

tw `gr', note(`note') legend(off)

end

polysameplot 1 2
*************

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Miranda Kim
Gesendet: Montag, 10. August 2009 11:01
An: statalist@hsphsun2.harvard.edu
Betreff: st: changing the legend in twoway function

Hi,
Can anyone help me with this?
I am trying to write a program that plots the functions a + bx + cx2 (on
the same graph), where a, b and c are stored variables. I want to label
the legend with the set of values a, b and c for each graph.
For example if I have:
a   b   c
1   3   4
2   5   8
then I want to have "a=1, b=3, c=4" and "a=2, b=5, c=8" assigned to the
relevant graph in the legend. How can I do this? Also , how complicated
would it be to control the colours or line types of the graphs?

My current program is as follows:

program define polysameplot

foreach i of numlist `0' {
local gr "`gr' function y=a[`i']+b[`i']*x+c[`i']*x^2, range(-5
5) ||"
}
twoway `gr'

end

polysameplot 38 39 40 41

I use Stata 10.

Thanks a lot for your help!

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```