Thank you, Señor Dans for this thought-provoking article.
About 15 years ago, here in the U.S., the State of Louisiana faced a similar "brain drain" situation, which resulted in top students graduating and leaving the state for better opportunities and many others leaving secondary education (high school) altogether (aka "dropping out") because of 1) a lack of educational planning that included students, parents, and guidance counselors, 2) a one-size-fits-all approach to post-secondary, i.e. four-year university isn't for everyone, and 3) a lack of information about employers in their areas and their staffing needs.
I was fortunate to be part of a program called StudentBuilder in which the state, educators, and employers worked together to assess each student's aptitude, link aptitudes to federal career descriptions and other data, counsel students and parents about educational options leading to these careers, e.g. community colleges, two-year degrees, trade schools, etc, require each student to have an educational plan that included the courses needed to pursue these options, and making students aware of employers in their areas that hire for these careers, which provided motivation.
I'm certain that the situation in Spain differs in significant ways, but I wonder if a similar "virtuous circle" approach might be attempted?