[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: A tricky graph to make
David Epstein wrote
> I have data I'd like to make into a graph, but I don't know if it's
> possible. The data have democracy scores between -10 and 10 for
> countries when they enter and leave the data set. For instance:
> Country Year Score
> ======= ==== =====
> AFG 1955 -10
> AFG 2000 -7
> ANG 1976 -7
> ANG 2000 -3
> ARG 1955 -1
> ARG 2000 8
> meaning that Afghanistan entered in 1955 with a score of
> -10 and left in
> 2000 at -7, Angola entered in 1976 at -7 and left in 2000
> at -3, etc.
> I'd like to make a graph with year on the x-axis, democracy
> score on the
> y-axis, plot two points for each country denoting the
> democracy levels
> they had when they entered and left the data set, and have these two
> points connected by a line. (Without the last requirement,
> it would just
> be a scatter plot, of course).
> Is there a way to do this in Stata? I've been looking at
> the Graphics
> book, but can't figure it out.
And there were various suggestions.
Dimitriy V. Masterov
> I think one quick and dirty way of doing this
> may involve reshaping the data:
> . twoway (connect score year if country=="AFG") (connect score year
> if country=="ANG") (connect score year if country=="ARG")
> If I correctly understand what you want to do,
> you might find Nick Cox's
> "linkplot" (-findit linkplot-) to be very useful.
A -reshape- is not necessary, and it's not especially quick compared
with other solutions.
Friedrich's solution is clearly correct in principle, but
would be a pain in practice with lots of panels. As stated,
we are cycling through Afghanistan, Angola, Argentina, ... and
we would be pretty tired of typing by the time we got to Zimbabwe.
There are, however, ways of automating the repetition of the elements.
-linkplot- from SSC does allow another solution without
repetition of elements.
. linkplot score year, link(country)
However, in this case you would probably be fine with
. sort country year
. connected score year, c(L)
-linkplot- is more general than the last; it makes sure
that you don't get spurious connections whenever (in this
case) the last
date of one panel does not follow the first date of the next
panel, but that's probably not an issue with these data.
Yet another solution which postdates -linkplot- is
to declare the dataset as panel data
. tsset country year
. xtline score, overlay legend(off)
-xtline- was added to official Stata on 12 September.
* For searches and help try: