Hi,
I'd like to produce five graphs - one for each state - while excluding bars with zero-frequency. The code below achieves it:
I'd also like to combine the graphs using a single legend, despite them having different legends. Any suggestions?
Thank you
I'd like to produce five graphs - one for each state - while excluding bars with zero-frequency. The code below achieves it:
Code:
levelsof state, local(state)
local vlname: value label state /* Local list of value labels */
local i=1
foreach s of local state {
local vl: label `vlname' `s' /* Local value label for state=s */
preserve
use taxes_paid, clear
keep if state==`s'
bysort taxes: egen tot=total(taxes_paid)
*drop if tot==0
graph bar taxes_paid if tot!=0, over(taxes, sort(1) descending) ///
ysc(r(0 1)) yla(0(0.2)1) ///
blabel(bar, format(%4.0f) size(small)) asyvars ///
legend(rows(3) size(small) position(6) ) scheme(modern) ///
ytitle("") title("`vl'" ///
, span size(medium)) graphregion(color(white) lwidth(vsmall)) ylabel(,angle(h)) name(f`i', replace)
local ++i
restore
}
Thank you
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input byte(key state taxes taxes_paid)
1 1 1 0
1 1 2 1
1 1 3 0
1 1 4 0
1 1 5 0
2 2 1 1
2 2 2 1
2 2 3 0
2 2 4 0
2 2 5 0
3 3 1 0
3 3 2 0
3 3 3 1
3 3 4 0
3 3 5 0
4 4 1 1
4 4 2 1
4 4 3 1
4 4 4 0
4 4 5 0
5 5 1 1
5 5 2 1
5 5 3 0
5 5 4 0
5 5 5 0
6 5 1 1
6 5 2 1
6 5 3 0
6 5 4 0
6 5 5 0
7 4 1 1
7 4 2 1
7 4 3 1
7 4 4 0
7 4 5 0
8 5 1 1
8 5 2 1
8 5 3 1
8 5 4 0
8 5 5 0
9 1 1 0
9 1 2 0
9 1 3 0
9 1 4 0
9 1 5 0
10 3 1 1
10 3 2 0
10 3 3 0
10 3 4 0
10 3 5 0
11 5 1 1
11 5 2 0
11 5 3 1
11 5 4 1
11 5 5 0
12 5 1 1
12 5 2 1
12 5 3 0
12 5 4 0
12 5 5 0
13 5 1 1
13 5 2 1
13 5 3 1
13 5 4 0
13 5 5 0
14 5 1 1
14 5 2 1
14 5 3 0
14 5 4 0
14 5 5 0
15 5 1 1
15 5 2 0
15 5 3 1
15 5 4 1
15 5 5 0
16 5 1 1
16 5 2 0
16 5 3 0
16 5 4 0
16 5 5 0
17 2 1 1
17 2 2 1
17 2 3 1
17 2 4 0
17 2 5 0
18 5 1 1
18 5 2 0
18 5 3 1
18 5 4 1
18 5 5 1
19 5 1 1
19 5 2 0
19 5 3 1
19 5 4 0
19 5 5 0
20 5 1 1
20 5 2 1
20 5 3 1
20 5 4 0
20 5 5 0
end
forvalues i=1/5 {
la def state `i' "State `i'", modify
la def taxes `i' "Tax `i'", modify
}
la val state state
la val taxes taxes
replace taxes_paid=100*taxes_paid
save taxes_paid, replace

Comment