Gender segregation in the labor market may be explained by women's re-luctance to choose technical occupations, although the foundations for career choices are certainly laid earlier, during education. Educational experts claim that female students are doing better in math and science and are more likely to choose those subjects if they are in single-sex classes. Possible explanations are the lack of self-confidence of girls in male-dominated subjects, the domi-nating behavior of boys in the classroom and unequal treatment by teachers. In this paper, we identify the causal impact of gender composition in coedu-cational classes on the choice of school type for female students. We propose that girls are less likely to choose a female-dominated school type at the age of 14 after spending the previous years in classes with a higher share of female students. We address the problem of endogenous school choice by using nat-ural variation in gender composition of adjacent cohorts within schools. The results are clear-cut and survive powerful falsification and sensitivity checks: Females are less likely to choose a female-dominated school type and more likely to choose the technical school type if they were exposed to a higher share of girls in previous grades. Our paper contributes to the recent debate about coeducation either in certain subjects or at the school level.