Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Allan Reese (Cefas)" <allan.reese@cefas.co.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: How do create a multi-line time series - alternative methods |

Date |
Wed, 21 Sep 2011 17:36:16 +0100 |

> On 20 Sep 2011, at 20:04, Haillie Lee <nal@princeton.edu> wrote: > ... can't seem to figure out how to fit multiple series for > different countries in one graph +label different series by country name. Nick Cox suggested xtline, which is one good solution. However, it's quite easy with the basic twoway scatter command, using the connect( L ) option. Here's an example using the xt system example data. sysuse xtline1, clear // you can copy this into the do file editor sort person day // these values already in order, but for general use ... scatter calories day, c(L) ms(i) // makes a plot similar to xtline, but all lines same colour separate cal, by(person) g(cll) // so split into variable per person scatter cll1 cll2 cll3 day, c(L L L) ms(i i i) // and you can choose any subset of people ... scatter cll? day, c(L L L) ms(i i i) // ... or the less-typing approach With fewer data points you might want to mark each line with symbols. It's also nice to put the line label at the end of the line, rather than in a legend. One method is to position text boxes by hand, but an automated approach picks the last plotted value for each line. gen namelab=person // person is 1,2,3 with attached labels replace namelab=0 if person==person[_n+1] & calories<. label values namelab person label define person 0 " ", modify // may be preferred just to create a string variable scatter calories day, c(L) ms(i) mlab(namelab) xscale( range(15341 15750) ) I had to extend the X range to keep the label within the plot area. When subsets of the data cover different X ranges, you have to sort the subsets so the largest X in one group isn't smaller than the smallest X in the next, or c(L) will join them. Allan * * 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/

- Prev by Date:
**Re: st: Using variable label** - Next by Date:
**Re: st: Re: ergodic distribution from transition probaility matirx** - Previous by thread:
**st: Yahoo! Auto Response** - Next by thread:
**[no subject]** - Index(es):