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]

st: Any way to suppress bar value labels in a graph if less than a specified value?


From   [email protected]
To   [email protected]
Subject   st: Any way to suppress bar value labels in a graph if less than a specified value?
Date   Wed, 18 Sep 2013 15:02:55 -0400

I work in a school district with over 100 schools, and a common task I have
is making graphs for annual reports on each school. I use Stata to loop
over schools to automate these kinds of repetitive and otherwise extremely
time-consuming tasks. A problem I commonly run into, though, is needing to
suppress value labels conditional on some rule (e.g., if smaller than x).
For instance, I'm currently making a stacked bar chart based on data
available in aggregate form only, and I have to suppress value labels in
the graph that are below 7.0%. I'm hoping there's a simple solution out
there. :) Below is an example of this issue, using the auto dataset.

(I'm using Stata 13 MP)

sysuse auto, clear

* Here, I'm just making up some aggregate data so we end up with a dataset
similar to the one I'm working with
gen pct_standfail = .
gen pct_standpass = .
gen pct_standexcel = .

replace pct_standfail = 4.87 if foreign == 1
replace pct_standpass = 80.88  if foreign == 1
replace pct_standexcel = 14.25 if foreign == 1

replace pct_standfail = 10.22 if foreign == 0
replace pct_standpass = 83.06 if foreign == 0
replace pct_standexcel = 6.72 if foreign == 0

duplicates drop foreign, force

/*
Ok, so now we have a wide dataset with each case representing a group
(domestic or foreign).
And we have 3 variables with values representing percentage of cases in
that group that
failed/passed/exceeded some standard of performance.

Below is my code for a stacked bar chart adapted to this data. I'm using
the blabel option to display values
in the center of each bar. The challenge I'm having is in figuring out how
to suppress the bar label when the value is below 7%
I can't seem to figure out a way to do this other than opening the graph
and deleting the smaller values
by hand. With over 100 schools and many different variations on this kind
of graph to produce,
I would love a code-based conditional solution that will save me tons of
tedious work. :)

Any ideas?
*/

graph bar pct_standfail pct_standpass pct_standexcel,  ///
	stack over(foreign, label(labsize(4.5) axis(noline) ) ///
	gap(*.5)) outergap(*.75) ///
	blabel(bar, position(center) color(white) size(5) format(%9.1f)) ///
		bar(1, fcolor(128 0 0) lcolor(black)) ///
		bar(2, fcolor(180 180 180) lcolor(black)) ///
		bar(3, fcolor(0 0 0) lcolor(black)) ///
	title("Performance Standard Y", size(8) margin(0 0 3 0) color
(black)) ///
	legend(off) ///
	yscale(range(0(20)100)) ylabel(0 "" 20 "" 40 "" 60 "" 80 "" 100
"", ///
	format(%9.0f) angle(0) labsize(1) labcolor(white) tstyle(major)
nogrid) ///
	graphregion(color(white) fcolor(white) lcolor(white)) ///
	plotregion(color(black) fcolor(white) lcolor(white)) ///
	xsize(1.0) ysize(1.7)





Matthew D. Lovelace, Ph.D.
Research and Evaluation
Gwinnett County Public Schools
Instructional Support Center, Suite 1.520
437 Old Peachtree Road NW
Suwanee, GA 30024-2978
Phone 678.301.7365 | Fax 678.301.7088
[email protected]

------------------------------------------------------------------------------------------------

NOTE: Email is provided to employees for the instructional and
administrative needs of the district. Email correspondence to/from
a district email account may be considered public information and
subject to release under Georgia laws or pursuant to subpoena.

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