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]

Re: st: need graph help


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: need graph help
Date   Tue, 19 Apr 2011 16:56:48 +0100

I don't know how luck enters into this. More importantly, you don't
say what graph commands you tried, so it is not clear what you did
wrong.

Given the size of the dataset I would

collapse obese, by(male year)
separate obese, by(male)
label var obese0 "female"
label var obese1 "male"
line obese? year, yla(0 0.1 "10" 0.2 "20" 0.3 "30") lcolor(pink blue)

As your example text shows, you are calculating numbers like 0.1 but
are thinking of them as 10%, etc. so adjusting your axis labels might
be what you want.

Note that you could go

egen mean =  mean(obese), by(male year)
separate mean, by(male)
label var mean0 "female"
label var mean1, "male"
line obese? year, yla(0 0.1 "10" 0.2 "20" 0.3 "30") lcolor(pink blue)

but that would be millions of data points, not many distinct.

egen tag = tag(male year) would help, but I would go for -collapse-.

On Tue, Apr 19, 2011 at 4:37 PM, Averett, Susan L
<[email protected]> wrote:
> Hi all: I am trying to do something that should be easy but I haven't had any luck. I simply want to graph the mean obesity proportion in my data over time by gender. In Stata I have the following. How can I make this into a line graph where I am graphing the trend in proportion obese over time? I really just want to graph the means below with year on the X-axis and proportion obese on the Y by gender. So for 1987, 12 percent of females were obese and 11.9 percent of males were obese. that would be the data point for 1987 etc.
> Can anyone help?
> thanks,
> Susan
>  bys male year: sum obese
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1987
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     18642    .1200515    .3250305          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1988
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     21035    .1196577    .3245686          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1989
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     24042    .1309791    .3373845          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1990
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     30193    .1412579    .3482932          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1991
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     31815    .1494578    .3565448          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1992
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     34753    .1541162    .3610653          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1993
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     47973    .1466033    .3537137          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1994
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     49118    .1548923    .3618057          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1995
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     52918    .1605503    .3671191          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1996
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     56520    .1685775    .3743816          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1997
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     61517    .1753824     .380297          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1998
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     67286    .1896531    .3920295          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 1999
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     71781    .1985484    .3989099          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2000
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     82714    .2096018    .4070269          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2001
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     92157    .2175961    .4126135          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2002
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    109993    .2233142    .4164691          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2003
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    120083     .239093    .4265314          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2004
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    141768    .2457536    .4305347          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2005
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    165126    .2617395    .4395829          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2006
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    164577    .2654198    .4415578          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2007
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    203739    .2776837    .4478576          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 0, year = 2008
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    197200    .2800862    .4490423          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1987
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     13410    .1111111    .3142814          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1988
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     14794    .1145059    .3184355          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1989
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     17409    .1214314    .3266374          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1990
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     20501    .1234574    .3289695          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1991
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     23050    .1321475    .3386584          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1992
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     25337    .1441765    .3512755          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1993
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     37200    .1413441    .3483808          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1994
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     36956    .1502598    .3573307          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1995
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     40289    .1602671    .3668581          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1996
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     42970    .1647428    .3709526          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1997
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     47021    .1750494    .3800134          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1998
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     50974    .1881547    .3908395          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 1999
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     53615    .2021822    .4016312          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2000
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     61648    .2116533    .4084836          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2001
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     69159    .2214896    .4152523          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2002
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     80422    .2298252    .4207229          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2003
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     85560    .2381954    .4259818          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2004
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |     97931    .2452033    .4302098          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2005
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    112038    .2605812    .4389537          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2006
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    111176    .2692218    .4435574          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2007
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    133048    .2802372    .4491167          0          1
>
> ------------------------------------------------------------------------------------------------------------------
> -> male = 1, year = 2008
>
>    Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>       obese |    129781    .2848106    .4513259          0          1
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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