Buy scenario, free maintenance and no property taxes: Living in a $2.7M house means a downpayment of $540,000 plus $6.6k/month of mortgage (assuming 2% interest rate on ~$2.2M mortgage paid over 40 years). Your housing prices increase 6%/year on average (1985 - 2015 average, http://www.doctorhousingbubble.com/california-housing-histor...). You sell 40 years later your house for $22,628,579.
Rent scenario: You put your $540,000 plus $4400 per month into your average stock market. 1985 to 2015 the performance was more than 10% per year (http://www.moneychimp.com/features/market_cagr.htm). Let's say you're conservative and you go for 6%/year in growth. In 40 years your net worth is $77,737,237.02.
Renting is definitely better than buying in the scenari outlined in grandparent's comment.
Also, I was considering a number of tail risks in our decision. For example, I'd bet that the house in the Bay Area will be worth roughly $0 in 40 years, because:
1.) Tech will have run its course, leading to a Detroit-like situation where everybody moves out and you can't sell what you've got.
2.) The housing stock here is objectively terrible by the standards of anywhere else in the country - many were cheaply built in the 1950s to 1970s, and they need major repairs and upgrades now, let alone in 40 years. Friend of mine was recently buying and was like "I offered $279K over asking on a house that needs at least $100K of repairs", and he didn't get it anyway.
3.) Termites are endemic here. Every house has termites and few of them have concrete basements. There's a good bet that the house you just spend $2.7M on doesn't actually have a foundation.
4.) Earthquakes and wildfires. The big tech companies assume that there is a 100% chance that the Bay Area will be hit by a major earthquake in the next 30 years; I don't see why I should assume any differently.
I moved here in 2009 and there was a big drop in house prices then, enough that everyone who bought in the boom years of 2004-2007 went underwater and many were foreclosed upon. Yes, I'm kicking myself for not buying then - though honestly, the money was in Google stock options instead and Google stock has gone up a lot more than Silicon Valley housing prices, so I probably still ended up ahead.
It's not irrational to want to have some diversification, particularly when things work out fairly well anyway.
As long as appreciation + inflation over the period you stay in a house you buy is greater than your interest rate, buying a house is effectively free (minus the downpayment). People bring up maintenance, however this is already taken into account with rental price increases, vs. a fixed 30 year mortgage. Maintenance is an overplayed expense, honestly.
EDIT:
I can't reply to the children comments, but I just want to say that the situation mention is absurd.
1. 2.7M worth of 1985 S.F. property would be entire neighborhoods and give you more than 6%. Forget houses, 2.7M in 1985 would buy you acres of prime real estate.
2. Even if it did not, it's not necessary to put down 20% on a house.
3. Investing and purchasing a house are not mutually exclusive strategies.
4. Overall, over 40 years buying will always be better.