Choosing an Identity: A General Model of Preference and Belief Formation