Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Graph of two grouping variables


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Graph of two grouping variables
Date   Tue, 20 Dec 2011 14:16:30 +0000

-catplot- (SSC) automates this.

Nick

On 20 Dec 2011, at 13:43, Lars Folkestad <lfolkestad@health.sdu.dk> wrote:

Dear List
My data was set up like this
Cause of death            age_gr
1                1
2                2
3                3
4                4
5                5
6                6
7                7
8                8
9                9

After googleing and a little crying i found this:
http://stata.com/statalist/archive/2008-05/msg01072.html

Then i did the following:
. gen frequency = 1
. graph bar (sum) frequency, over(group) over(age_gr) asyvars

That did the trick.

Merry christmas!

Lars


Den 20/12/11 13.51 skrev "Scholes, Shaun" <s.scholes@ucl.ac.uk>:

This sounds like something I was playing with a couple of weeks ago. I came up with the following to match one of the figures in a paper I was
reading:

ID year cause1 cause2 cause3 cause4 cause5 cause6 cause7
1    1    150    25    28    31    13    7    77
2    2    125    38    28    38    12    3    55
3    3    129    38    38    27    26    16    71
4    4    134    35    47    28    20    19    68
5    5    103    39    31    24    27    21    68

label define yearlbl 1 "1981" 2 "1986" 3 "1991" 4 "1996" 5 "2001"
label values year yearlbl

graph bar (asis) cause1 cause2 cause3 cause4 cause5 cause6 cause7,stack
over(year) ///
legend(order(1 "CHD" 2 "Lung" 3 "Cancer" 4 "Lungdis" 5 "Injury" 6
"Suicide" 7 "Other")) ///
ytitle("Title") ylabel(0 100 200 300 400,ang(hor)) bar(1,color (black))
bar(2,color(gray)) title("Males",pos(11))

I'm a novice with graphs...but this seemed ok for my purposes. So age
group would replace 'year' in this example; and you would have 12 causes
rather than 7.
Feel free to ignore: it may not be what you are looking for. Would be
very interested, however, to know your final solution!

Shaun







-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Muhammad Anees
Sent: 20 December 2011 12:19
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Graph of two grouping variables

Then I would suggest to take hints from
http://www.stata.com/support/faqs/data/percentvars.html

On Tue, Dec 20, 2011 at 5:07 PM, Lars Folkestad
<lfolkestad@health.sdu.dk> wrote:
Dear Muhammad and Nick
Thank you for your fast answers.
I actually want something like the asyvars shown here
http://www.ats.ucla.edu/stat/stata/faq/barcap.htm
But i cannot figure out how to do it with two categorical variables
and to count the data so that i get on the y-axis the sum of
obeservations with in the 12 categories within the different age
groups (0-100) lars

Den 20/12/11 12.54 skrev "Nick Cox" <njcoxstata@gmail.com>:

-tabplot- (SSC) pushes the very simple idea of two-way bar charts. I
am not clear that it is what you ask for, but it could be useful
nevertheless. The bars don't touch by default, but that's tunable.

Nick

On Tue, Dec 20, 2011 at 11:47 AM, Lars Folkestad
<lfolkestad@health.sdu.dk> wrote:
Dear list

I have two variables (causes of death and age groups) And i want to
present them as a bar - chart.

The idea is that the x axis will contain the age groups 0 10 20 30 ...
100
years

For every age group i want the total number (or percent) of
observation within the 15 categories i have defined so that if 10
persons died of causes within category 1 there will be a spike of 10
on the y axis, and similarly for the other categories.

The variables are:
Cod is an integer of 1-12

And age_gr: integer from 0-100 in 10 year intervals

Hope that made sense.

lars


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

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


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



--

Best
---------------------------
Muhammad Anees
Assistant Professor/Programme Coordinator COMSATS Institute of
Information Technology Attock 43600, Pakistan http://www.aneconomist.com

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



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


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