If you buy a basket of stocks like an index fund at an overall peak in the market, it can take quite a while for those stocks to recover their value, much less gain additional -- a decade or more. And most people don't have that kind of patience. In general, the transaction costs of selling a home (6% commission!, never mind what you have to do to prepare it for sale in terms of cleaning, getting the yard fixed up, repairing everything you let slide, "staging" it, and living somewhere else while you wait for it to sell, which seems to happen to a lot of people) are such that just breaking even requires about a 10% appreciation. This is raw truth behind the don't-buy-if-you-are-planning-on-moving-i
If you live in commuting distance of a city like Boston or Seattle, or in Silicon Valley, it is impossible to imagine owning a home for a decade or more and _not_ making money when you sell. You just cannot find a decade where you'd lose. But this is not true for large blocks of the country (take northern Maine -- really! Take it! No one else wants it.). While it is hard to imagine a future in which commuting distance of Boston or Seattle or Silicon Valley is not in-demand . .. wait. No, actually, it's pretty easy to imagine a future in which commuting distance is not in demand. It's quite easy to imagine a future in which gas prices are so prohibitive everyone desperately moves as close to their job as they can, tolerating cramped conditions not seen since the 1950s.
One might conclude from this that living in the city is a great idea and can only go up. Yeah, you haven't been paying attention to how pessimistic this is, have you? That whole living-in-the-city thing is pretty recent. We've already had one or two major waves of new condo construction with ridiculous build quality problems. We've seen condos sell for a third their original value because of water problems.
Bottom line: the home-as-investment idea has some problems. Don't buy if you are planning on moving in 5-7 years. Buy in an area where you have some confidence you will be able to find another job if your current job goes away. Take into consideration possible commute-cost inflation greatly in excess of recent inflation. And think long and hard before buying new construction. It costs a premium, and has unknown problems that you'll have to try to get the builder to fix. With previous owners, they have to tell you about all the problems and if they don't, you can go back and sue them. While it may seem counterintuitive, it is sometimes easier to get the money out of a previous owner than it can be to get a builder who well and truly fucked up to make it right.