An old adage that many programmers stick to is "It takes a certain type of mind to learn programming, and not everyone can do it."

Now I'm sure that we all have our own trove of anecdotal evidence, but has this been studied scientifically?

Yes, there's a pretty famous paper online designed to more or less determine "Who is cut out to be a programmer."
A cognitive study of early learning of programming - Prof Richard Bornat, Dr. Ray Adams

All teachers of programming find that their results display a 'double
hump'. It is as if there are two populations: those who can [program],
and those who cannot [program], each with its own independent bell
curve.
Almost all research into programming teaching and learning have
concentrated on teaching: change the language, change the application
area, use an IDE and work on motivation. None of it works, and the
double hump persists.
We have a test which picks out the population
that can program, before the course begins. We can pick apart the
double hump. You probably don't believe this, but you will after you
hear the talk. We don't know exactly how/why it works, but we have
some good theories.


Here's a blog post by Jeff Atwood that interprets the results and puts some things into context.

Despite the enormous changes which have taken place since electronic
computing was invented in the 1950s, some things remain stubbornly the
same. In particular, most people can't learn to program: between 30%
and 60% of every university computer science department's intake fail
the first programming course.
Experienced teachers are weary but never
oblivious of this fact; brighteyed beginners who believe that the old
ones must have been doing it wrong learn the truth from bitter
experience; and so it has been for almost two generations, ever since
the subject began in the 1960s.

