# st: Re: by-graph

 From Itsik Dvir To statalist@hsphsun2.harvard.edu Subject st: Re: by-graph Date Sun, 02 Mar 2003 17:25:10 +0200

 Tom Steichen and Stata-list users  Thanks for the advice and the code by Tom Steichen. It plots all scatter data on a single graph. However, I was interested in combining these groups on 4 separate graphs as by-graph does: one for each group and one for all data. So, based on Tom's code and the STATA command "gr combine" and "saving" it was doable. The code is given bellow: twoway (scatter y x if group==1) (lfit y x if group==1) , saving(group1) ytitle("") xtitle("") legend(off) note("") ylabel(0(.1)1) xlabel(0(.1)1, nolabels) title("group1", box bexpand)) ysize(4) xsize(4) twoway (scatter y x if group==2) (lfit y x if group==2) , saving(group2) ytitle("") xtitle("") legend(off) note("")  ylabel(0(.1)1, nolabels) xlabel(0(.1)1, nolabels) title("group2", box bexpand)) ysize(4) xsize(4) twoway (scatter y x if group==3) (lfit y x if group==3), saving(group3) legend(off) note("") ytitle("") xtitle("") ylabel(0(.1)1) xlabel(0(.1)1) title("group3", box bexpand) ysize(4) xsize(4) twoway (scatter y x) (lfit y x ), saving(group) legend(off) note("") ytitle("") xtitle("") ylabel(0(.1)1, nolabels) xlabel(0(.1)1) title("All", box bexpand)) ysize(4) xsize(4) gr combine group1.gph group2.gph group3.gph group.gph, l2title(" y ") b2title(" x ") ysize(4) xsize(4) I think there is a simpler way to deal with the xlabel and ylabel using the "ycommon" and "xcommon" options of the gr_combine command, but I have not tried it, yet.   Many thanks for the help   Itsik       ------------------------------Date: Fri, 28 Feb 2003 15:33:42 -0500From: "Steichen, Thomas" Subject: st: RE: by-graphItsik Dvir writes:> I want to make the two changes in the following by-graph command> > twoway (scatter y x ) (lfit y x ) , by(group, total  )> > suppose group contains three subsets of the data.> 1. eliminate the fitted line in just one individual graph, > while still displaying the scatter x-y data.> 2. change the default title of the total graph ("Total") to say "All" ..> > Can anyone give an advice?You would need to manually create the parts. The following assumesgroups have numerical values 1, 2 and 3 and group 3 does not needthe fitted line (but is not tested!): twoway (scatter y x, if group==1) (lfit y x, if group==1) ///        (scatter y x, if group==2) (lfit y x, if group==2) ///        (scatter y x, if group==3)                         ///        (scatter y x)              (lfit y x)              ///  legend(label(1 "Group 1 data")   label(2 "Group 1 fit")  ///         label(3 "Group 2 data")   label(4 "Group 2 fit")  ///         label(5 "Group 3 data")                           ///         label(6 "All data")       label(7 "All fit") )You likely would want to name these better and would have to play around with symbol and line colors.  Tom