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: Question about graph bar


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Question about graph bar
Date   Thu, 28 Jul 2011 20:46:38 +0000

<>

If you had an over() grouping, you could use the sort() sub option, but that doesn't seem to mesh with your data structure.  One quick way I know to get the sorting to work in this case is to use -statplot- (from SSC; use -findit- or type -ssc install statplot-  ) of which I am an author.   Here's an example:
*********
//create some fake data:
clear
set obs 100
forval n = 1/10 {
	g q`n' = rbinomial(1, .4)
	}
	g one = 1

//graph w. statplot:
preserve
**for bar labels:
forval n = 1/10 {
	replace q`n' = 100*q`n'
	}

statplot q1-q10, varopts(sort(1)) blabel(bar) ytit(% Answ. Yes)
restore
*********

- Eric

On Jul 28, 2011, at 3:32 PM, O'Brien, Rachel H wrote:

> Hi.  I am trying to create a bar graph for the means of 10 different variables.   Each variable is an indicator for whether or not the survey respondent answered yes to a question (and the respondent could have said yes to multiple questions).  I would like STATA to order the bars (variables) by the mean (most frequent --> least frequent).  Is there an option or anything that will do this?  I know I can do this manually by ordering the variables in the graph bar command based on their means, but I thought I would check if there is a more automatic way.
> 
> Thanks!
> 
> Rachel O'Brien
> 
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index