Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: A tricky graph to make


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: A tricky graph to make
Date   Wed, 15 Oct 2003 10:39:35 +0100

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:
> ...

Friedrich Huebler

> . twoway (connect score year if country=="AFG") (connect score year
> if country=="ANG") (connect score year if country=="ARG")

David Miller

> 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

and

. xtline score, overlay legend(off)

-xtline- was added to official Stata on 12 September.

Nick
n.j.cox@durham.ac.uk

*
*   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/



© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index