[Robert Shiller] compiled data in 2006 showing that between 1890 and 2004, the return on investing in houses was just 0.4 percent a year—a period when the stock market grew at 9.6 percent annually. And in a paper this June in the journal Real Estate Economics, two researchers calculated that over the past 30 years, most often it would have been better to rent than buy. Renters who invested in stocks and bonds instead of home equity came out ahead 75 percent of the time.I know I'm rehashing here, but the calculation for rent vs. buy is not hard, and has next to nothing to do with the stock market. I'll deal with the second part first since every time I hear someone compare housing to the stock market I want to beat them with a copy of the Wall Street Journal (a much better use of the Journal than reading it).
If you rent instead of buy, then all of your mortgage payment doesn't suddenly go into the stock market. A decent fraction of that goes to a rent and is lost (-100% ROI!!!), so getting an extra 10% on the remainder doesn't really offset unless the rent is much much less than the mortgage. This should be to keep in mind, but just, so often: FAIL. You must live somewhere. If you are comparing buying to renting then you need to keep track of ROI of buying vs. ROI of RENTING, not the fucking stock market. The stock market only enters in with the extra, and then only if you can guarantee that you will park all the extra in the stock market and not just some of it.
The ROI for buying compared with renting is very dependent on not just the monthly relative payments but also the length of stay, and possibility of selling/renting. If you are going to be someplace for 2 years, buying is likely a very bad option. Between closing costs, very low principle payoff and generally very little appreciation, you are likely to lose money, more so than if you were to rent. The exception here is if you can buy a house/condo that you could then rent out after that, in which case, it may still be the better option.
I'm not going to rehash the rest of the ROI work or rent vs. buy since it is available here and here and here. I really just want to make clear, that, from reading them, any article that talks about renting being better than buying is really just making that case as buying as a substitution for other investment, not as a substitution for renting (no matter how hard they try to do this).