In the first part of the thesis (Chapters 1 to 4), we analyze the near-universal gender gap reversal in secondary and tertiary education. In virtually all countries, males show a greater dispersion in ability test scores relative to females. We show that this simple fact, combined with an increase in the returns to education across cohorts, is sufficient to reproduce the gender gap reversal observed internationally. We bould a model that generates a hump-shaped relationship between the enrollment rate in education and the female-to-male ratio among the enrolled that is consistent with the data. From time-series data on enrollment rates in education by sex, we generate country estimates for gender di erences in ability distribution using our model. Our estimates highly correlate with cross-country gender differences in test score distributions found in PISA. We also assess the validity of our theory against two alternative explanations for the gender gap dynamics: changes in social norms, and improvements in females' relative performance at school over time. The data does not support the predictions of the alternative hypotheses, while bringing further support to our theory. In the second part of the thesis (Chapter 5), using Finnish high school data, I examine the relationship between peer composition and the causal e ect of school choice on high school exit examination outcomes. To discern the causal effect of school choice, I exploit over 300 regression discontinuity designs that result naturally from the Finnish educational system that allocates pupils to high schools according to their ninth grade grade point average and announced preferences. I find strong evidence that high school choice matters in Finland and that it is related to peer composition. The class composition effect, however, is associated with peer homogeneity rather than average peer quality. I find that a standard deviation change in the homogeneity of peers is positively associated with a 0.02 to 0.13 standard deviation change in the exam results. I also find that the average effect of being marginally above the entrance threshold reduces slightly but significantly the performance of the pupil. This unexpected finding might be a sign of overconfidence on the part of the pupils in making their school choice.