We suggest a new method for detecting patterns of social clustering based on choice data. The method compares similar subjects within and between cohorts and thereby allows us to isolate the effect of peer influence from that of exogenous factors. Using this method on Norwegian register data, we address the question of whether students tend to cluster socially based on similar background. We find that common background correlates with making the same choices of curricular tracks, and that both exogenous preferences and peer influence matter. This applies to immigrant students from the same country, and, to some extent, to descendants of immigrants, but not to students from culturally similar countries. There are also small effects related to parents' education and income.