I think the issue is more that sf people are rich for the country but not rich for the bay area so they just rent.
With leverage the computation gets a bit more complex, but basically you're paying 4.5% interest on 7% appreciation, and not needing to pay rent, so you may get 4-5% real returns. Lever up 5x with a 20% down payment and you get about 25% returns - competitive with Google, but in the same ballpark, and you've taken on the risk of foreclosure or being underwater if there's a housing bust (which happen periodically in the Bay Area and take prices down 10-40%).
The stock is a lot more liquid, you can take it anywhere, you can sell it whenever you want, you can move in with a girlfriend and keep it. If you haven't made a conscious decision to stay in the Bay Area, the stock performs much better.
And it's down to 2.5% interest or even lower for 30 year fixed for some people.
Sort of how a bond’s value moves inverse to yields.
I honestly don't know what the next decade will bring. I would personally bet on high inflation, so that 2.5% mortgage rate will likely be a negative real interest rate. (Hence, I bought.) Stock returns may or may not equal the previous decade's, as well.
look at the 2012 to 2016 period for example of rent vs purchase. if you just bought an average condo and sold it you basically could've ended up staying for free vs. renting.
As an example if you invested in tech stocks only from 2012 to 2016 you would have had enough money to buy 3 condos.
There are quite a few techies who move to SF, work for the hot unicorn for 4 years, and live extremely cheaply. They don't buy housing because they don't intend to stay in SF (and besides, who wants to buy a house in SF?), but when they "retire" they've got a few million in stock options. They can buy a house, they just don't want to, because their living situation is temporary.
I suspect that a lot of the housing boom going on around the country now is because the rich techies in SF no longer have to stay in SF.