I seek advice about how to set legend appearance in the case of
multiply overlaid graphs.
For each of a series of variables (obs represent different groups), I
have summary statistics calculated from 13 waves of a panel survey --
one variable is the summary statistic calculated from all 13 waves
combined ("All"), a second is the summary statistic calculated from
waves 1-7 ("w1-w7"), and so on, through to the ninth variable which
shows the summary statistic calculated from waves 8-13 ("w8-w13").
For each group, I would like to show the "All" statistic as a point,
and then the pooled summary statistics from the different time periods
as a connected line. Something like: x x--x--x etc.
Drawing the chart is straightforward using overlaid -connected- and
-scatter-. The problem is that I can't get the legend as desired. I
want it to appear only once for each series. Currently I can get it to
appear twice for each group (once for the -connected- and once for the
-scatter-) or not at all.
Suggestions please. The following code illustrates the points .
clear
input pcch_eq0-pcch_eq7
1.578541 -21.92812 9.329963 -23.90232 -1.492552 30.60662
-19.78882 -24.73903
1.645614 -28.84015 5.253359 -28.02497 -2.472513 24.23796
-19.78882 -34.91605
1.37921 -30.06525 7.988371 -30.06525 -2.472513 33.70157
-27.95978 -34.91605
1.421728 -30.06525 10.19743 -28.53089 -1.83553 33.70157
-19.49391 -30.80389
1.750973 -21.55178 11.43951 -25.30849 .4068476 33.30109
-27.95978 -25.30849
1.791185 -17.12838 11.92909 -19.49391 1.323474 31.53796
-21.11412 -18.64264
1.534512 -11.83217 11.92909 -18.64264 -.1627967 31.53796
-27.95978 -18.01183
1.389061 -13.58221 12.76805 -18.64264 -1.492552 33.70157
-27.95978 -18.64264
1.484615 -5.896193 12.76805 -18.01183 4.826205 33.30109
-28.46585 -17.12838
end
ge byte point = _n in 1/9
lab var point "Waves used"
lab def point 1 "All" 2 "w1-w7" 3 "w2-w8" 4 "w3-w9" 5 "w4-w10" 6
"w5-w11" 7 "w6-w12" 8 "w7-w13" 9 "w8-w13"
lab val point point
twoway (connected pcch_eq0 point if point > 1, msym(O) ) ///
(connected pcch_eq1 point if point > 1, msym(X) ) ///
(connected pcch_eq2 point if point > 1, msym(D)
lpattern(shortdash) ) ///
(connected pcch_eq3 point if point > 1, msym(T) lpattern(dash)
) ///
(connected pcch_eq4 point if point > 1, msym(d)
lpattern(shortdash) ) ///
(connected pcch_eq5 point if point > 1,
msym(dh)lpattern(shortdash) ) ///
(connected pcch_eq6 point if point > 1, msym(t) lpattern(dash)
) ///
(connected pcch_eq7 point if point > 1, msym(th)
lpattern(dash) ) ///
(scatter pcch_eq0 point if point == 1, msym(O) ) ///
(scatter pcch_eq1 point if point == 1, msym(X) ) ///
(scatter pcch_eq2 point if point == 1, msym(D) ) ///
(scatter pcch_eq3 point if point == 1, msym(T) ) ///
(scatter pcch_eq4 point if point == 1, msym(d) ) ///
(scatter pcch_eq5 point if point == 1, msym(dh) ) ///
(scatter pcch_eq6 point if point == 1, msym(t) ) ///
(scatter pcch_eq7 point if point == 1, msym(th) ) ///
, xlabel(1 2 3 4 5 5 6 7 8 9, valuelabel) ///
yline(0) ytitle("Percentage change in income, wave t to t+1")
///
ymtick(-40(5)40) legend( region(lstyle(none)) )
saving(junk1.gph, replace)
twoway (connected pcch_eq0 point if point > 1, msym(O) ) ///
(connected pcch_eq1 point if point > 1, msym(X) ) ///
(connected pcch_eq2 point if point > 1, msym(D)
lpattern(shortdash) ) ///
(connected pcch_eq3 point if point > 1, msym(T) lpattern(dash)
) ///
(connected pcch_eq4 point if point > 1, msym(d)
lpattern(shortdash) ) ///
(connected pcch_eq5 point if point > 1,
msym(dh)lpattern(shortdash) ) ///
(connected pcch_eq6 point if point > 1, msym(t) lpattern(dash)
) ///
(connected pcch_eq7 point if point > 1, msym(th)
lpattern(dash) ) ///
(scatter pcch_eq0 point if point == 1, msym(O) legend(off) )
///
(scatter pcch_eq1 point if point == 1, msym(X) legend(off) )
///
(scatter pcch_eq2 point if point == 1, msym(D) legend(off) )
///
(scatter pcch_eq3 point if point == 1, msym(T) legend(off) )
///
(scatter pcch_eq4 point if point == 1, msym(d) legend(off) )
///
(scatter pcch_eq5 point if point == 1, msym(dh) legend(off) )
///
(scatter pcch_eq6 point if point == 1, msym(t) legend(off) )
///
(scatter pcch_eq7 point if point == 1, msym(th) legend(off) )
///
, xlabel(1 2 3 4 5 5 6 7 8 9, valuelabel) ///
yline(0) ytitle("Percentage change in income, wave t to t+1")
///
ymtick(-40(5)40) legend( region(lstyle(none)) )
saving(junk2.gph, replace)
graph combine junk1.gph junk2.gph
Stephen
-------------------------------------------------------------
Professor Stephen P. Jenkins <[email protected]>
Director, Institute for Social and Economic Research
University of Essex, Colchester CO4 3SQ, U.K.
Tel: +44 1206 873374. Fax: +44 1206 873151.
http://www.iser.essex.ac.uk
Survival Analysis using Stata:
http://www.iser.essex.ac.uk/teaching/degree/stephenj/ec968/
Downloadable papers and software: http://ideas.repec.org/e/pje7.html
Learn about the UK's new household panel survey, the United Kingdom
Household Longitudinal Study: http://www.iser.essex.ac.uk/ukhls/
Contribute to the consultation on content:
http://www.iser.essex.ac.uk/ukhls/consult/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/