Hi All,

I am using twoway to generate a scatterplot with an lfit overlay for several individual units, and would like to have the color of the lfit line match the color of the markers for each unit.

In the following example, I have only two units (domestic and foreign), so I could have done it manually (i.e. with mcolor() and lcolor()) . As this is intended for many units, and many different colors will be used, this will have to be performed via code.

Thanks in advance!

Ariel

Code:
sysuse auto, clear
tw(scatter weight mpg if foreign ==1)(lfit weight mpg if foreign==1)(scatter weight mpg if foreign ==0)(lfit weight mpg if foreign==0)