How Circumstances Shape the Friendships We Keep