Many people wonder, "If I'm only going to live somewhere for a few years, should I rent rather than buy a house?" That may be a good strategy. Let's say you buy a house and then have to sell it within two to three years. The various buying and selling costs alone will probably amount to a significant amount of money. Will the house have appreciated enough to cover those costs? It's possible, but not guaranteed. Heck, just as with the stock market, over a short period of time, the value of your investment may even decline.
Also, remember that in the first years when you're paying off a traditional mortgage, your payments are mostly going toward interest, not toward building equity (paying off the principal balance). So, after living in the house for only a few years, you'll probably technically own just a tiny part of it.
Renting is always an option to consider. It's true that mortgage interest is tax-deductible, and it can be cost-effective to own rather than rent. But, if you're renting a place for considerably less than you'd have to cough up in mortgage payments, you might invest the difference and profit through stocks rather than real estate. Renters also don't have to pay for new roofs and water heaters.
If you're pretty sure that property values will go up significantly in the near term, you may do well buying instead of renting. But no one really knows what the short-term future holds.
Learn more about buying, selling, and maintaining a home in these articles: