Earlier quoted context omitted.
The real opportunity cost is not living somewhere else. Run the math and SF is best avoided.
That's true in the US. In other areas, leaving the city might not be a realistic option. Consider Hong Kong as an (extreme) example, where leaving the city means emigrating to another country with another language etc. (yes, HK is technically a Special Administrative Region of China, but can be considered standalone in this respect). The median apartment price/income ratio here is 18, compared to a US average of 3.9…
What is worse, this cancer got exported to mainland China in the 1990s and it was systematically rolled out for all major cities there. $1.8m buys you an 80sqm new apartment in Shanghai in an below average location, when the median household income in Shanghai is definitely lower than US$20k.
It is lucky to be living in HK as there are still public housing options. In cities like Shanghai and Beijing, using the national household median income figure, a Chinese peasant needs to start saving the deposit from the Ming Dynasty (1368–1644) to be able to afford an average apartment there.