A new census of the 0.2 < z < 3.0 universe. I. The stellar mass function