Large cities produce more output per capita than small cities. This higher productivity may occur because more talented individuals sort into large cities, because large cities select more productive entrepreneurs and firms, or because of agglomeration economies. We develop a model of systems of cities that combines all three elements and suggests interesting complementarities between them. The model can replicate stylized facts about sorting, agglomeration, and selection in cities. It also generates Zipf’s law for cities under empirically plausible parameter values. Finally, it provides a useful framework within which to reinterpret extant empirical evidence.