Mothers can adjust the sex of their unborn children to best match their living conditions, research shows.