Changing Bar Labels Using the Stata Graph Editor

By Kuai Kaui Wang · Published 4 November 2026
graphicsstata

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

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

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
}

Note: The gr_edit command is an undocumented Stata command that allows you to take graph editor changes and apply them with command code interactively or in a do-file. Please contact us at tech-support@surveydesign.com.au to learn more.

11 views 0 found this useful