That is not an accurate representation of the research. See this public summary of a (sadly, paywalled) HBR paper on the subject [https://hbr.org/2016/08/why-do-so-many-women-who-study-engin...]. At every stage of the educational pipeline, a chunk of women do indeed drop out. The cause, however, is often an encounter with sexist culture along the way.

The subject of insecurity does come up:

> Throughout college, men and women succeeded equally in the classroom. However, we observed that women started to doubt their problem-solving abilities more than men. [...skipping long illustrating quote]. Women were also much more likely to look to others—teaching assistants, professors, and advisors—to affirm, and reaffirm, their confidence. Men did talk about doubting themselves, but they did not necessarily seek reassurance from others. We found that this search for positive cues carried over into expectations for feedback from supervisors in internships and jobs."

However, it is not at all the only phenomenon at play. More discouraging is the gendered treatment they receive from professors and, more importantly, colleagues.

> For many women engineering students, however, their first encounter with collaboration is to be treated in gender stereotypical ways, mostly by their peers. While some initially described working in teams positively, many more reported negative experiences. When working with male classmates, for example, they often spoke of being relegated to doing routine managerial and secretarial jobs, and of being excluded from the “real” engineering work. Kimberly wrote, “Two girls in a group had been working on the robot we were building in that class for hours, and the guys in their group came back in and within minutes had sentenced them to doing menial tasks while the guys went and had all the fun in the machine shop.”

> There were also descriptions of being treated differently by professors. Rachel described when her team (the only all-girl team) won second place in a design competition: “Our professor wanted to get a picture of our prototype and us. We picked up our prototype and were all smiling and looking all professional; then he said: ‘You guys look like professional catalog models; this picture could go in a catalog and you could sell big time.’”

> Men, on the other hand, described mandatory group design projects as exciting turning points, where theory and practice come together. “I made a pretty big stroke of progress last week,” one student wrote in his semi-monthly diary, “I ended up proving the professor wrong on something she had done last year, which actually helped us find better results (well, also more correct results)… It’s really a blast working on something like that.”

Anyway, there are more quotes available, if you want to look at it yourself.

Note also that there is one other factor they address that isn't related to sexism in the field (but perhaps to broader sexist acculturation in society) - women are more likely to want to work somewhere that is "contributing to society". Part of what's going on here is that it's not considered quite as socially acceptable for women to be ambitious for ambition's sake, at least not in the way that it is for men. But I don't think that's something that the engineering culture enforces, I think that's something that's internalized.