We compare the effects of selective and nonselective secondary education on children's test scores, using British data from the National Child Development Study. Test scores are modeled as the output of an additive production function. An important input is the child's unobserved initial endowment, which may be correlated with the education system attended. In this model, we generalize the difference-in-differences approach and identify the entire counterfactual distribution of potential outcomes. Our results suggest that the better performance of selective schools relative to nonselective ones is essentially due to differences in pupils' composition.