Research into the obvious, but someone has finally done it: Three women researchers have studied the behavior of undergraduates in STEM fields, and concluded that there basically is no problem. From the abstract:

"The results show that high school academic preparation, faculty gender composition, and major returns have little effect on major switching behaviors, and that women and men are equally likely to change their major in response to poor grades in major-related courses. Moreover, women in male-dominated majors do not exhibit different patterns of switching behaviors relative to their male colleagues."

Furthermore current recruitment efforts to attract more women tend to be counterproductive. In an interview, the primary author says:

"Society keeps telling us that STEM fields are masculine fields, that we need to increase the participation of women in STEM fields, but that kind of sends a signal that it's not a field for women, and it kind of works against keeping women in these fields."

One of our female students told me that the women are interviewed endlessly, for one project or another: "tell us about your experience", "are you doing ok", "have you experienced sexism", and on, and on. That alone is enough to make them question their career choice.