Changing bar labels using the Stata graph editor

The type of bar labels is limited in Stata graphs but sometimes additional information is required. This can be added with the Stata graphics editor commands. Below the number of observation for each region is added. Here is the worked example:

The commands I used in a do-file are:

sysuse citytemp, clear

#delimit ;
graph bar tempjuly tempjan, over(region) bargap(-30)
legend( label(1 "July") label(2 "January") )
ytitle("Degrees Fahrenheit")
title("Average July and January temperatures")
subtitle("by regions of the United States")
note("Source:  U.S. Census Bureau, U.S. Dept. of Commerce")
blabel(bar, position(inside) format(%9.1f) color(white)) ;
#delimit cr

generate No=_n
collapse (sum) N, by(region)
list

local i1=1

forvalues i=1/`=_N' {

	gr_edit plotregion1.barlabels[`i1'].text = {}
	gr_edit plotregion1.barlabels[`i1'].text.Arrpush N=`=No[`i']'
	local ++i1

	gr_edit plotregion1.barlabels[`i1'].text = {}
	gr_edit plotregion1.barlabels[`i1'].text.Arrpush N=`=No[`i']'
	local ++i1

}

exit


If you would like to know more on Stata graphs, please have a look at the book A Gentle Introduction to Stata, Sixth Edition.

29 views

© 2020 by Survey Design and Analysis Services. 

  • LinkedIn
  • Facebook
  • Twitter
  • YouTube