Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Recursive graph with parallel lists


From   Roberto Ferrer <[email protected]>
To   Stata Help <[email protected]>
Subject   st: Recursive graph with parallel lists
Date   Sun, 7 Jul 2013 14:02:21 +0100

I want to customize the way in which I draw connected (line) graphs
for different years of a particular variable. Now I have this and for
only four years it works just as intended:

twoway connected college_mean size_b if college == 0 & yearobs == 1975, ///
msize(tiny) lpattern(solid) sort ///
|| connected college_mean size_b if college == 0 & yearobs == 1985, ///
msize(tiny) lpattern(shortdash) sort ///
|| connected college_mean size_b if college == 0 & yearobs == 1995, ///
msize(tiny) lpattern(dash) sort ///
|| connected college_mean size_b if college == 0 & yearobs == 2005, ///
msize(tiny) lpattern(longdash) xlabel(0(1)10) sort ///
title("Proportion with at least college by city size") ///
legend(label(1 "1975") label(2 "1985") label(3 "1995") label(4 "2005"))

But I would like to be able to easily add/delete as many years as I'd
like (I have aprox. 40 years). I would like something along the lines:

y = list(1975 1996 2000)
t = list(dash longdash shortdash)
l = list(label1 label2 label3) [which could be simply the elements of y]
Graph xvariable yvariable using y
labels using l
options (line types, e.g.) using l

At the moment I have this code using parallel lists:

local years = "1975 1985 1995 2005"
local linet = "solid shortdash dash longdash"
local marker = "tiny"
local n : word count `years'

forvalues i = 1/`n' {
    local y : word `i' of `years'
    local ll : word `i' of `linet'
    twoway connected college_mean size_b if college == 0 & yearobs == `y', ///
    msize(tiny) lpattern(`ll') sort ||
}

but this doesn't even give me a desired result because in the loop,
the previous graph gets substituted by the new one. Also, no line
patterns are included, nor the legend, which is vital for me.

Ideally, I would be able to also specify the year list as, e.g.
(1975-1986 1999 2002). Of course there would not be enough line
patterns for all these years but in that case, I would do with the
default colors.

Thank you for your consideration.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index