An endogenous model of hierarchical government