Investment and merging as an endogenous coalition formation game