Endogenous formation of partnerships with moral hazard