Agglomeration bonus and endogenous group formation