Hello,
In the following code example, I encode a string variable (in this case the variable make from auto.dta), so that I can use it in a -twoway- graph. However, I would like xlabel in my graph to display the original string variable values. Is there a way to do this?
In my example the encoded variable is makenum=1 where make=="Chev. Chevette".
I would like the graph xlabel to display the string var rather than the encoded numeric var.
I have tried using Nick Cox's -labmask- but perhaps that is not the correct approach.
In the following code example, I encode a string variable (in this case the variable make from auto.dta), so that I can use it in a -twoway- graph. However, I would like xlabel in my graph to display the original string variable values. Is there a way to do this?
In my example the encoded variable is makenum=1 where make=="Chev. Chevette".
I would like the graph xlabel to display the string var rather than the encoded numeric var.
I have tried using Nick Cox's -labmask- but perhaps that is not the correct approach.
Code:
sysuse auto, clear sample 8 encode make, gen(makenum) label(makenum) tab make sort make bysort foreign: egen trunkmin = min(trunk) bysort foreign: egen trunkmax = max(trunk) bysort foreign: egen trunkmedi = median(trunk) format trunkmedi %9.2g l make trunkmin trunkmedi trunkmax labmask makenum, val(make) lab var makenum "Make" label define labtrunkmin "Trunk size" label variable trunkmedi "Median" label variable trunkmin "Range" label variable trunkmax "Trunk size" twoway (rcap trunkmax trunkmin makenum, sort msize(medium)), /// title(Trunk size:) /// subtitle(Range & Median) /// legend(pos(5) ring(0) col(1)) /// scheme(sj) /// xlabel(#6, angle(thirty_five)) /// ylabel(0(4)20, format(%9.0f)) /// xtitle("Make") /// ytitle("Trunk size (cu ft)") /// name(trunkmedi, replace) legend() || /// scatter trunkmedi makenum
Comment