Dear Stata users,
I use -catplot- (SSC) command to graph bar plot. In the code below, option percent(party) allows me to show percents for each distinct category defined by variable party. So far it's all right, however, I want to sort those bars according to percents that shown by percent(party). And the option var1opts() and var2opts() only allows me to sort bars on percents of party or occupation in the overall (we can get the resultes using tabulate party, sort or tabulate occupation, sort). Is there anyone can guide me to solve this problem? Thank you.
I use -catplot- (SSC) command to graph bar plot. In the code below, option percent(party) allows me to show percents for each distinct category defined by variable party. So far it's all right, however, I want to sort those bars according to percents that shown by percent(party). And the option var1opts() and var2opts() only allows me to sort bars on percents of party or occupation in the overall (we can get the resultes using tabulate party, sort or tabulate occupation, sort). Is there anyone can guide me to solve this problem? Thank you.
Code:
catplot party occupation, var2opts(sort(1) descend) percent(party) blabel(bar, format(%9.1f))
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(party occupation) 1 3 2 1 1 1 2 2 2 1 2 2 1 1 1 1 2 1 1 1 2 . 1 1 1 1 2 2 1 2 1 1 2 5 1 1 2 4 2 4 2 4 2 4 2 4 1 1 2 1 1 1 1 1 2 1 2 1 2 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 4 2 2 2 1 2 4 2 1 2 4 2 4 2 2 2 1 1 2 2 1 2 1 2 4 2 5 2 5 2 5 2 6 2 5 2 5 2 5 2 5 2 5 2 3 2 3 2 5 2 3 2 5 2 5 1 1 2 1 1 1 2 4 1 1 1 1 1 1 2 4 2 4 2 4 2 4 2 4 2 6 1 3 1 1 1 3 1 1 1 1 1 2 1 1 1 1 2 3 2 3 1 1 1 1 1 1 1 1 1 1 1 . 1 1 1 1 2 3 1 1 end label values party party label def party 1 "democratic", modify label def party 2 "republic", modify label values occupation occupation label def occupation 1 "manager", modify label def occupation 2 "worker", modify label def occupation 3 "selfemp", modify label def occupation 4 "student", modify label def occupation 5 "famer", modify label def occupation 6 "parttime", modify
Comment