I've looked at this many times, and I have done A LOT of research. Ultimately, buying may not be more better than renting, and vice versa. It really depends. The NY Times has a very good Buy vs Rent calculator:
http://www.nytimes.com/interactive/business/buy-rent-calcula...
I highly suggest using it to determine whether to buy or not. The biggest problem, though, is there are some assumptions that need to be made that can drastically affect the outcomes. Most importantly: average annual appreciation in rents and home prices. Another is average annual returns on investments and rates of inflation.
The best way to figure these out are to find historical data. I use Redfin to look at houses currently on the market and prices sold 20 to 30 years ago. I also go to the local city hall to look at housing records. For rents, I do a lot more analysis. Anyways, the bottom line is, housing prices should not and usually DO not appreciate faster than inflation. More specifically, median wage growth. And why is this? Because if housing prices increased faster than wage growth, even by 1%, then after 40 years, housing would no longer be affordable. I don't see why people have such a hard time understanding this. I personally like this blog:
http://michaelbluejay.com/house/appreciation.html
He also has a really good buy vs rent calculator with some decent assumptions. You will want to check regional differences, because, obviously, SF and NYC are places that may differ a bit in terms of appreciation and inflation rates. Anyways, I would suggest anyone who is interested in the buy vs rent argument to read that, and then look at their local appreciation rates for housing prices/rent. Assume 2.5% inflation. And then, make a very conservative estimate on the returns of their portfolio (4%). I would then plug and see what the calculators say. I like Michael's calculator more than the NY Time's calc, by the way:
http://michaelbluejay.com/house/rentvsbuy.html
It goes past 30 years.
Also, if you're making an apples to apples comparison, I've found that typically, buying is way better than renting. However, if you're making an apples to oranges comparison, renting a 1/2Br apt. vs buying a 3Br house, it usually always turns out that renting is better than buying. I've done this calculation many times, and invariably, that's what I've learned.