The Dynamics of Group Formation