Emergence of cooperatives and farmer heterogeneity