This topic is much of a cliche, at least for native residents coming from these two places.
From the official point of view, Beijing and Shanghai are always prioritized as the first and second city of the oldest continuous civilization in the world.
But the comparison between residents, as well as all other aspects about the two cities, has constantly brought into hot debate, on the internet, in the press, or by word-of-mouth.
While the rest of the world think fairly high of both cities, Beijingnese and Shanghainese look down upon each other fiercely, as they do with other ethnic Chinese, the latter attitude being actually understandable, since they simply stand out, as the elite groups of richer, better-educated, more open-minded people.
As far I can tell, the special feeling of superiority towards specifically the other group of folks can be generalized as follows: Beijingnese are disgusted with Shanghainese's overdone snobbery, shrewdness and standoffishness, while Shanghainese hates Beijingnese's forever brag and boast and boorishness.
I surely don't think any of this would be totally it or would do any justice to either side. And I'm not gonna buy any of the arbitrary conclusion that either Beijing or Shanghai is a better place.
But have I mentioned a customary saying I overheard the other day? The whole sentence can be loosely translated into: Beijing is China's Beijing, Shanghai is the World's Shanghai.
This makes much sense to foreigner visitors, for whom it's simply a matter of choice. If you wanna take in some insight into the profound ancient Chinese culture, Beijing is the place to be. If you wanna conquer the culture shocks with ease, invest on Shanghai.