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: Stacked and Unstacked Variables in Graph Bar


From   Hendrik Worschech <[email protected]>
To   [email protected]
Subject   Re: st: Stacked and Unstacked Variables in Graph Bar
Date   Fri, 19 Apr 2013 21:17:18 +0200

Thank you Nick for the quick response.

I understand the concept. I was hoping for an easier way, though as I
have a lot more than just 10 observation and about 50 variables in my
dataset.

But I will find a calm minute, sit down, and make sure to restructure
it that way.

On Fri, Apr 19, 2013 at 8:37 PM, Nick Cox <[email protected]> wrote:
> Some technique here:
>
> * sandpit to play in
> clear
> set obs 10
> gen year = 2010 + (_n > 5)
> foreach v in a b c {
> gen `v' = ceil(6 * runiform())
> }
>
> * restructure!
> stack a year b year c year , into(all year) clear
> label define _stack 1 a 2 b 3 c
> label val _stack _stack
> gen which = _stack > 2
> graph bar (sum) all,  over(_stack) over(which, label(nolabels))
> over(year)  nofill asyvars
>
> Nick
> [email protected]
>
> On 19 April 2013 19:16, Hendrik Worschech <[email protected]> wrote:
>
>> I have a panel with, lets say, 10 individuals over 5 years and three
>> variables (a, b & c).
>>
>> I would like to have the sum (of all individuals) of a & b stacked
>> together as one bar and the sum of c by itself next to it. And this
>> should be repeated for each year.
>>
>> I've come across this example, but in my case I don't want to separate
>> by observations but by variables. I don't know how I could separate
>> the variables a&b from c with over:
>>
>> webuse union, clear
>> keep idcode year age
>> gen which = cond(year == 71 | year == 77, 1, cond(year == 88, 2, .))
>> graph bar age, over(year) over(which) asyvars stack
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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