Bookmark and Share

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, is already up and running.

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

RE: st: twoway graph, with by and combine

From   "Hoffman, George" <>
To   "" <>
Subject   RE: st: twoway graph, with by and combine
Date   Sun, 1 May 2011 10:12:49 -0500

Thank you Eric. I'll build a wrapper for this since I would like to issue this repetitively for the dataset.


-----Original Message-----
From: [] On Behalf Of Eric Booth
Sent: Sunday, May 01, 2011 10:01 AM
To: <>
Subject: Re: st: twoway graph, with by and combine


You can specify each line separately with an -if-:
 sysuse auto, clear
 tw (lfit price mpg if rep78==1) (lfit price mpg if rep78==2) ///
  (lfit price mpg if rep78==3, lpattern(dash)) (lfit price mpg if rep78==4, lpattern(dot))

**or build the command using macros 
**** to avoid manually typing all categories of your ID:

 levelsof rep78, loc(ll)
 foreach v in `ll' {
 	loc gr (lfit price mpg if rep78==`v')  `gr'

tw (scatter price mpg) `gr' ,  ///
/* you can differentiate the lines by 
changing the lpatterns,
or you can edit the label 
with an option like: */ ///
 	legend(on order(1 "Dots" 2 "Rep78 Category 2" 3 "three"))

- Eric
Eric A. Booth
Public Policy Research Institute
Texas A&M University
Office: +979.845.6754

On May 1, 2011, at 9:44 AM, Hoffman, George wrote:

> I've got panel data  and want to display the by(id) linear fit lines  on one graph.
>         twoway (fit y x, by(id)) 
> works, but gives different plots for all id's.  combine is not an option for by in this command.
> Is there a quick way, or user-written way, to get the above on one graph? 
> Seems simple, but I can't find it.
> Thank you in advance
> George Hoffman
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index