In this paper, I assess the extent to which the gender gap in physician earnings may be driven by physicians' preference for working with specialists of the same gender. By analyzing administrative data on 100 million Medicare patient referrals, I provide robust evidence that doctors refer more to specialists of their same gender, a tendency known as homophily. I propose a new measure of homophily that is invariant to differences between the genders in the propensity to refer or receive referrals. I show that biased referrals are predominantly driven by physicians' decisions rather than by endogenous sorting of physicians or patients or by gender differences in the labor supply. As 75% of doctors are men, estimates suggest biased referrals generate a 5% lower demand for female relative to male specialists, pointing to a positive externality for increased female participation in medicine.