When you went through the process of buying a home for the first time, you probably were a little nervous about making monthly mortgage payments for 30 years. You may have even had second thoughts about the entire purchase. But then you may have heard that real estate investing was a great idea, and your fears about owning a home evaporated.

But is homeownership really such a good deal as an investment? Or should you be putting your money in the stock market instead?

Recently, two researchers at the Atlanta Federal Reserve set out to answer that question. They analyzed returns of home prices against returns in the stock market (setting aside the value of the mortgage interest tax deduction, the forced savings that comes with paying a mortgage, and the relative cost of renting vs. buying) going back to 1926. They chose an 87-year time period to even out some of the ups and downs in securities and housing markets.

How they did it

The researchers, Atlanta Fed economists Ellyn Terry and Jessica Dill, asked two important questions to help them assess whether housing is a good investment:

  1. With average returns so close to zero, just how often has the housing market produced losers?
  2. How does investing in housing compare to investing in equities?

They did not look at the “buy and hold” strategies popular among investors seeking cash flow from rents. Instead, they looked only at appreciation.

Terry and Dill computed the average annual return of home prices across all possible combinations of start and stop points using the Shiller house price series from 1926 to 2012. They found that 80 percent of all start-stop point observations experience some degree of positive return.

To take into account the duration of ownership, they assumed that the average homeowner lives in his or her home for 13.3 years, based on analysis by Paul Emrath at the National Association of Home Builders.

For comparison, they looked at the S&P 500 Index (as a representation of the stock market) and compared the average annual returns in stocks to the average annual returns in housing.

The findings

How long you stay matters. The average annual returns for an asset held for a period of 13 or more years, according to the study, is substantially less volatile than for an asset held for fewer than 13 years. Those investing for the longer term were much more likely to have positive returns.

The study also found that 50 percent of homes owned for less than 13 years had negative annual returns compared to 12 percent for homes owned 13 years or more.

More years of ownership could mean smaller returns. Despite the better odds for positive returns for homes owned 13 years or more, Terry and Dill found that the average annual return was actually slightly higher for those owning for fewer than 13 years.

So, if you buy and stay for a while, you’re more likely to see a positive return on your investment than you would if you sold right away—but that return might be smaller than it would have been had you sold earlier.

The stock market may still offer a better return on investment. The study found that investing in equities offers favorable returns more often than investing in housing.

While there is more volatility in terms of return, that volatility comes with an opportunity for larger gains over time. According to the study, the weighted average annual return of the S&P 500 is 4.55 percent compared to 0.97 percent for the Shiller real home price index.

“It’s important to note that the distributions of returns for housing in all these computations are not the distribution of returns for every possible house purchase,” Terry and Dill wrote in the study. “Likewise, the returns shown for the S&P 500 are not the entire universe of returns from buying and selling individual stocks. Instead, these returns are based on a pool of housing and a pool of stocks.”

Is the investment worth it?

These findings might leaving you wondering, “If I can see a larger return in the stock market than I can in the real estate market, should I bother buying a home? Shouldn’t I just put my money in the stock market?”

The answer depends on your personal circumstances, but there are certain things to consider.

Today, real estate values are appreciating, and rents are rising. While you can see a return on your home’s increased value, you won’t see any return on your higher rent payments.

In fact, according to Jed Kolko, chief economist at Trulia, homeowners who buy a home today and hold it for seven years can expect to pay 44 percent less than people who choose to rent.

There are other perks to homeownership, too. You may be able to benefit from the mortgage interest deduction, and paying down your mortgage is a kind of forced savings in the form of equity. This equity can be accessed when you sell the home, but it can also be accessed in the form of a home equity loan or cash out refinance. If you are the sort of person who finds it hard to save, you may appreciate the forced savings of a mortgage.

And at an average of 4.40 percent for a 30-year fixed-rate mortgage (according to Freddie Mac), you’ll be earning more in interest on that forced savings than you would if your cash were sitting in a savings account earning 1 percent in interest.

Alternatively, you can stay a renter and hope your stock market investments beat the cost of your annual rent increases, though such increases are on the high side these days—around 7 percent to 8 percent.

Before you make your final decision, take stock of your personal finances and spending habits to ensure you’re making the best choice for your situation.

Steve Cook is executive vice president of Reecon Advisors and covers government and industry news for the Reecon Advisory Report. He is a member of the National Press Club, the Public Relations Society of America, and the National Association of Real Estate Editors, where he served as second vice president. Twice he has been named one of the 100 most influential people in real estate. In addition to serving as managing editor of the Report, Cook provides public relations consulting services to real estate companies, financial services companies, and trade associations, including some of the leading companies in online residential real estate.