Objectively speaking, is the opportunity cost of doing a PhD in STEM higher than it was compared to decades ago?
The opportunity cost could be calculated only ex-post. So if you take a 1000 PhD students and determine their total earnings 5 years after their education vis-a-vis the alternatives, says a software engineer. And do a statistical analysis, only then, could you come to a conclusion. Perhaps you can look for such data and do the analysis if you want to be rigorous.
But that might not really be highly useful because there will be outliers and most of the choices we make in life, assuming we are motivated to be successful, is to become an outlier. We make decisions to pursue higher degrees like PhD with varying goals.
Most of the PhD aspirants wish to find a career in education -universities and colleges - requiring to fulfil the eligibility criteria. In their case, there is no value in calculating the opportunity cost as that is the career path which suits them.
Another group of aspirants pursue a PhD with the hope of building something which can bootstrap their career in innovation and entrepreneurship. You build a very good idea in academia and launch it as a product. Google is one such example. Silicon Valley is filled with such instances. If successful, the opportunity cost is not high. If you fail in this goal and then get back to the industry there is a high opportunity cost-- with a good chance that your boss was your junior in high school.
There is another notable group of PhD aspirants who pursue a degree in the hope of migrating to a newly developed country with better living standards. The host country either runs the universities, more as a business, raking in billions of dollars in tuition fees and then letting these PhD students work in the industry -- where they do not really mind doing even jobs which have got little to do with what they did in their PhD. Again, in this case the opportunity cost is very low -- considering their objective.
Going deeper into your question, or rather now addressing your actual question, has the opportunity cost changed over time. The opportunity cost has, with time, reduced, imo. I have known students who extend their Master's thesis into PhD and finish the whole work in less than 4 years after their Bachelors. In Europe, the average PhD duration is increasingly tending to three years though it is still 7-8 years in the US. Naturally, the opportunity cost in the US is high but so are the opportunities.
You can see that the opportunity cost is not just a function of time but also the region of the world and the ability/goal of the PhD aspirant.