In this paper I use a rich dataset in order to observe each student over time in different subjects and courses. Unlike most peer studies, I identify the peers and the teachers that each student has had in every classroom. This enables me to handle the simultaneity and selection problems, which are inherent in estimating peer effects in the educational production function. I use a value-added approach with lagged peer achievement to avoid simultaneity and extensive fixed effects to rule out selection. To be specific, it is within-student across-subject variation with additional controls for time-invariant teacher characteristics that is exploited. Moreover, I identify students that are attending classes in which they have no peers from earlier education which otherwise could bias the result. I find positive peer effects for the average student but also that there is a non-linear dimension. Lower-achieving students benefit more from an increase in both mean peer achievement and the spread in peer achievement within the classroom than their higher-achieving peers.JEL classification: I2