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

st: Re: simple (?) graph question


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: simple (?) graph question
Date   Fri, 16 Apr 2004 21:08:45 -0500

Twoways come to mind.  The first is to -reshape- the data into a long format
and then use -xtline-.    The second is to -xpose- the data and use -twoway
connect-  Examples below:

Example 1.

. l

     +---------------------------+
     | patient   value1   value2 |
     |---------------------------|
  1. |       1       51       48 |
  2. |       2       49       53 |
  3. |       3       47       59 |
     +---------------------------+

. reshape long value, i(patient) j(time)
(note: j = 1 2)

Data                               wide   ->   long
----------------------------------------------------------------------------
-
Number of obs.                        3   ->       6
Number of variables                   3   ->       3
j variable (2 values)                     ->   time
xij variables:
                          value1 value2   ->   value
----------------------------------------------------------------------------
-

. tsset patient time
       panel variable:  patient, 1 to 3
        time variable:  time, 1 to 2

. xtline value, overlay plopts1(recast(connected))
plopts2(recast(connected)) plopts3(recast(connected)) xlabel( 1 2)

Or, an alternative way to get the dots at each point

. xtline value, overlay xlabel( 1 2) plot(scatter value time) legend(order(1
2 3))


Example 2
. l

     +--------------------+
     | var1   var2   var3 |
     |--------------------|
  1. |    1     51     48 |
  2. |    2     49     53 |
  3. |    3     47     59 |
     +--------------------+

*Make sure the data are saved!

. xpose, clear

. drop in 1
(1 observation deleted)

. gen time = _n

. forv i = 1/3 {
  2. label var v`i' "Patient `i'"
  3. }


. twoway (connect v1 time) (connect v2 time) ( connect v3 time) , xlabel(1
2)


Hope this helps,
Scott


----- Original Message ----- 
From: <Jim.Seward@sunhealth.org>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, April 16, 2004 5:19 PM
Subject: st: simple (?) graph question


> All,
>
> I have a simple graph question.  I paged through the Graphics manual and
> looked at the pull down menu but can't figure out an answer.
>
> I have a small data set of before and after lab values on 20 individuals.
> I would like to do a dot graph with two values on the x-axis, "before" and
> "after", and the lab value on the y axis.  I would like to connect the
> before and after dots for each individual with a line, so I would have 20
> lines.
>
> The data are arranged:
>
> Patient #         Value 1      Value 2
> 1         51   48
> 2         49   53
> 3         47   59
> .
> .
> .
> and so on...
>
> Thanks, and have a good weekend,
> Jim Seward


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index