In this paper we examine whether students' and teachers' social identity play any role in the learning outcome of the students. More importantly, we ask if a student bene fits by learning from a teacher of the same gender. Unlike the existing literature which explains such interaction in terms of role model based effect, we explain such interaction in terms of gender based sorting across private and public schools. Our results are driven by two critical difference between male and female members. For male and female teachers, the difference comes from their differential opportunity costs of teaching in schools at remote locations. For students, the difference between male and female members comes from the differential return to their human capital investment by parents - where for girls, a lower fraction of the return comes to their parental families after they are married following patriarchal norm. These factors create a sorting pattern which leads to an impact of gender matching. We then test our theoretical results using survey data collected from Andhra Pradesh.