# Colouring bars in order of magnitude

Below is a worked example:

Please note that all bars not covered by the first and second places are considered (colored) as the third place.

The commands I used in a do-file are:

```
clear
input country gdp
1 100
2 110
3 240
4 50
5 10
end
list
gsort -gdp
gen gdpred=gdp if _n==1
gen gdpgreen=gdp if _n==2
gen gdpblue=gdp if _n>2
list
graph hbar gdpred gdpgreen gdpblue, over(country, sort(gdp) ///
descending) nofill legend(label(1 "Best") label(2 "2nd best") ///
label(3 "rest") rows(1)) bar(1, color(cranberry)) ///
bar(2, color(dkgreen)) bar(3, color(dknavy))
```

You may find the book __Speaking Stata Graphics __useful if you would like to know more on Stata graphs.