just like Stata's xtile, but faster