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

RE: st: Adding lines to graphs

Subject   RE: st: Adding lines to graphs
Date   Fri, 11 Nov 2005 09:18:58 -0500

Nick and Ulrich. Thanks for your help on this. Because the data for the graph
are generated by a specifically written program, Ulrich solution proved easiest
to integrate, and it works perfectly.


Quoting Nick Cox <>:

Alternatively, it is not necessary to change the dataset size.

Given y and x, you create two new variables:

gen y1 = 0 in 1
replace y1 = y[1] in 2
gen x1 = 0 in 1
replace x1 = x[1] in 2

line y1 x1 || line y x

Admittedly, you still have to mess around
with legends, line styles etc. So either
you alter your data a little, as above or
below, or you use -scatteri- as earlier


Ulrich Kohler wrote:
> I have a series of interconnected monotonically declining
plots that I am
> presenting as a single connected line graph, i.e., a graph
that starts
> relatively high on the y axis, declines, jumbs vertically
to a second high
> point, declines again,etc (substantively describes a
relationship between
> varying values of a hazard ratio and age). I can't figure
out how to add a
> line going from the 0 point on the x axis to the initial
value of the
> graph. I would be most appreciative of any suggestions. Thanks

I think you need to generate an observation with x=0.
Assuming that the y-value for x=0 should be y=0:

. set obs `=_N+1'
. replace x = 0 in `=_N'
. replace y = 0 in `=_N'
. connected y x, sort

Or, if your dataset contains only x and y:

. input
.  0 0
.  end
. connected y x, sort
*   For searches and help try:

*   For searches and help try:

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