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: 3 different categorical variables same graph


From   Marcos Vinicius <bioestatistico@inbox.com>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: 3 different categorical variables same graph
Date   Thu, 10 May 2012 09:25:04 -0800

Thank you Nick.Helped a lot.
Vinicius.

> -----Original Message-----
> From: n.j.cox@durham.ac.uk
> Sent: Thu, 10 May 2012 12:01:48 +0100
> To: statalist@hsphsun2.harvard.edu
> Subject: RE: st: 3 different categorical variables same graph
> 
> Here's the flavour of a -reshape- solution
> 
> sysuse auto , clear
> local lab1 "`: var label foreign'"
> local lab2 "`: var label rep78'"
> rename (foreign rep78) (catforeign catrep78)
> reshape long cat , i(make) string
> replace _j = "`lab1'" if _j == "foreign"
> replace _j = "`lab2'" if _j == "rep78"
> catplot cat _j , percent(_j) nofill recast(bar)
> 
> 
> Nick
> n.j.cox@durham.ac.uk
> 
> 
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
> Sent: 10 May 2012 08:33
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: 3 different categorical variables same graph
> 
> -catplot- is a user-written program from SSC. When offered three
> variables it looks for their cross-combinations. But it seems that you
> want three separate frequency distributions to be juxtaposed. If that
> is so, then it is simplest to produce them separately and -combine-
> them as in
> 
> sysuse auto
> catplot foreign, percent recast(bar) name(g1)
> catplot rep78, percent recast(bar) name(g2)
> graph combine g1 g2, ycommon
> 
> except that in your case there would be three graphs. An alternative
> is to -reshape- your data so that the three variables are combined
> into one.
> 
> Nick
> 
> On Thu, May 10, 2012 at 7:53 AM, Barth Riley <barthriley@comcast.net>
> wrote:
> 
>> See http://www.stata.com/support/faqs/data/percentvars.html
> 
> Vinicius
> 
>>> I am trying to generate a bar chart where I have 3 different
>>> categorical
>>> variables (var1,var2,var3)  on the X-Axis (Var 1 to Var 3 in the
>>> example
>>> below, letters identifies categories. The bar represents the proportion
>>> of
>>> the distribution.
>>> I have tried graph bar and catplot without success.
>>> catplot   var1 var2 var3,     ascategory percent blabel(bar,
>>> position(outside) format(%9.1f)) bargap(20)  vertical
>>> graph bar    var1 var2 var3,    asyvar  bargap(20)
>>> blabel(bar,position(outside) format(%4.2f))
> X>>            proportion
>>>> 
>>>>        ___
>>>>        | |
>>>>        | |                     ___             ___
>>>> ___       |
>>>>        | |             ___     | |             | |
>>>> | |       |
>>>>        |               | |     | |             | |             ___
>>>> ___     | |
>>>>        |       ___     | |     | |             | |     ___     | |
>>>> | |     | |     ___
>>>>        |       | |     | |     | |             | |     | |     | |
>>>> | |     | |     | |
>>>>        |       | |     | |     | |             | |     | |     | |
>>>> | |     | |     | |
>>>>        |       | |     | |     | |             | |     | |     | |
>>>> | |     | |     | |
>>>>        |       | |     |D|     |E|             |F|     |G|     |H|
>>>> |A|     |B|     |C|
>>>> 
>>>> 
>>>> --------------------------------------------------------------------------
>>>>                        Var     2                       Var     3
>>>> Var     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/
> 
> *
> *   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/

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium



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