Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Graphs (statalist-digest V4 #5049) - multiple lines on one graph


From   "Allan Reese (Cefas)" <allan.reese@cefas.co.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>, "estrellastata@gmail.com" <estrellastata@gmail.com>
Subject   st: RE: Graphs (statalist-digest V4 #5049) - multiple lines on one graph
Date   Tue, 29 Oct 2013 10:01:52 +0000

Answers so far appear to miss the point - except for suggesting reading the manual.
It's quite easy to put multiple lines on one graph and to mix point and line displays. The basic scatterplot command allows for multiple Y variables, and each one can have visible or invisible points and/or joining lines.

It sounds like one approach here may be to fit each regression and store the predictions as separate variables, then plot all three with one command.  I am assuming these are alternative models for the same Y v X variables.  If it's Y1 v X1, Y2 v X2, Y3 v X3 then three graphs in an array is probably sensible.

A variation on this is when a single regression model includes a factor variable, so "separate lines" are fitted to each level.  Here there may be one fitting command and one -predict- but you want to plot the lines as separate and definitely not join the ends!  The -separate- command will put Y values for each line into different variables.

Here are two examples.  Colours and tones can be varied to emphasize the data (points) or the model (lines).  The wildcard notation helps when there are multiple lines; here it would be as easy to write sep0 sep1.  How much metal do you get per buck in a car?

sysuse auto
regress wei pri
predict linear
g pr2 = price^2
regress wei pri pr2
predict quad
scatter wei lin quad pri, ms(oh i i) c(. l l) sort mcol(gs12) clcol(. blue orange)

regress wei  i.foreign##c.price
predict sep
separate sep, by(for)
scatter wei sep? pri, ms(oh i i) c(. l l) sort mcol(gs12) clcol(. blue orange) 

Have fun
Allan


>Date: Mon, 28 Oct 2013 12:10:39 +0100
>From: Estrella Gomez <estrellastata@gmail.com>
>Subject: st: graphs

>I have 3 linear graphs from the coefficients of a regression. I would
>like to put all this 3 lines into one single graph. I have tried graph
>combine, but then I obtain 3 different graphs into one picture. I
>don't need this, but the three different lines into one graph


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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index