>> Age and ability are not correlated
> ... cognitive decline..
I know this is not the age groups you thought about, but on the topic: I think they ARE correlated, but the other way: At 40 I have had time to get to know so ridiculously much more than someone starting out in their early 20s. And I see its effect very real, people in early 20s (generalizing ofc) can spend so long on things on have seen so many times...or spend more time making lots of bugs and finding them than just writing the code with fewer bugs.
Or spend their brain cycles on the "how to code" part of the job, instead of that just being second nature and focusing on the underlying ideas.
Or young people may be be competent coders, but completely baffled reading and really grasping underlying ideas in existing codebases (especially this I know I have progressed at with training over the years..)
I feel experience can be undervalued in our industry in a way it is not in others. It is valued... but not as much as I feel it should be..
Of course this effects drowns a bit in the noise of all of the programmers like the OP talks about that barely get by, in all age groups. But within the set of skilled coders... from what I have seen, I would always prefer working with the older to the younger to get a project done..
(Ofc there may be a point where this turns. I lack personal experience with coders 20 years older than myself.)