In elementary school, girls do as well as or better in math than boys. In middle school, Mertz and her colleagues suggest, girls with an inclination for math begin to lose interest and fall behind, mostly due to peer pressure and societal expectations. Throughout middle and high school, social stigma and lack of appropriately challenging educational opportunities for the mathematically precocious becomes a hard reality in most American schools. Consequently, gifted girls, even more so than boys, often camouflage their mathematical talent to fit in well with their peers.
It falls back on the whole societal stereotype that math, and by extension science, isn't cool and certainly not cool if a girl does it.
As for women leaving, The Athena Factor is a study to read. They researchers found that hostility of the workplace culture is the most important factor driving women out, with "63% of women in science, engineering and technology have experienced sexual harassment." The whole thing is worth a read, and can give some insight into why women don't stick around in IT or any science career.
I'm lucky in that I've worked in the public sector for most of my IT career, and I've not seen as much as what the study found.
The moon is made of green cheese. -- John Heywood