Statalist


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

RE: st: Graph bar using the over option


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Graph bar using the over option
Date   Wed, 25 Mar 2009 16:19:18 -0000

Please note that a similar question was asked on 13 February:  

<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist
.0902/date/article-543.html> 

And answered on the same day by Ulrich Kohler and myself: 

<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist
.0902/date/article-553.html> 

<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist
.0902/date/article-557.html>

Despite what you say, it is not obvious that the graph form you seek is
likely to be especially efficient or effective in showing changes over
time. 

You can get sum variables 

foreach v in variable1 variable2 variable3 variable4 { 
	egen sum_`v' = sum(`v'), by(timeperiod) 
} 

And then you can plot the sums directly by 

line sum_* timeperiod 

Nick 
[email protected] 

David Airey

Mess around and you'll get it, for example, see:

clear
input time var_4 var_5 var_6
1 10 20 30
2 20 30 40
3 30 40 50
end

graph bar var_4-var_6, over(time)

reshape long var_, i(time) j(variable)
graph bar var_, over(time) over(variable)

clear
input time response var
1 10 4
2 20 4
3 30 4
1 20 5
2 30 5
3 40 5
1 30 6
2 40 6
3 50 6
end

graph bar response, over(time) over(var)

On Mar 25, 2009, at 8:30 AM, Kate McAllister wrote:

> Does this mean I have to rearrange my data set? At the moment column 1
> contains my 'timeperiod' variable and then the other columns are my  
> other
> variables, with a total of three lines in my table. Is the answer to  
> have
> the timeperiods as different columns and the variables as different  
> rows?
> If so, is there a nice simple way of doing this (I have quite a few
> variables)

David Airey 

>> What you wanted is to have your times (ordered correctly) over your
>> variables, not your variables grouped by time, which is what you got.
>> The help file for graph bar talks about what you can expect under
>> different requests. You have to scroll way down to ``remarks'',
>> specifically where it gives pictures of year and division.

>> On Mar 25, 2009, at 6:58 AM, Kate McAllister wrote:

>>> I want to create a bar graph displaying several variables over 3
>>> different
>>> time periods. If I type:
>>> graph hbar (sum) variable1 variable2 variable3 variable4,
>>> over(timeperiod)
>>>
>>> then I get a graph that displays all the variable values for
>>> timeperiod1
>>> clustered together, then all the variable values for timeperiod2,
>>> and then
>>> for timeperiod3.
>>>
>>> What I actually want is a graph the displays the variable1 values
>>> over the
>>> three time periods, THEN the variable2 values over the three time
>>> periods,
>>> then  the variable3 values... and so on, all on one graph.

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