The Emergence of Learning Communities: A Theoretical Analysis