I'm not sure SF is a great example. For most tech workers, they're giving themselves a worse commute by living in the city rather than somewhere else in the South Bay closer, in many/most cases, to where their office is. So, yes, their jobs may be a major reason they're in the Bay Area overall, but mostly not in SF itself.
This is of course much less true in industries like finance.
This is of course much less true in industries like finance.