The most important thing that matters is ability to earn a decent living. Decent living is essentially ability to afford most things like a property in good neighborhoods, personal identity (clothes), transportation, quality education for children, and safety.
People are really smart and they optimise for their own survival. Essentially - decent wage -> better options for partner -> better standard of living.
In some countries, like Norway, a teacher makes a decent wage. Not as much as a software engineer, but good enough to support a pretty good lifestyle.
Where in some countries, like India, a stem graduate makes a LOT more money than a teacher. I made more money in my third year as a software engineer, than my father who worked in public sector as a civil engineer with 25+ years of experience. Comparison with non technical workers with stem fields is really lop sided when it comes to earning potential. Plus if you are possibly the first generation which can break out of poverty cycle for your entire family, then that adds another layer of pressure to choose certain fields. Hence men or women tend to choose these fields.
As wealth creation in some of these countries reaches to a point where non stem fields receive similar earning potential, already happening in India, we will see lower number of women opting for these fields as well.
We would really like to find a non economic reason for some of these disparities, like patriarchy, gender discrimination and so on, but it is probably mostly economic.