I hear some studies say the stock market is a better investment than real estate,
It's ALWAYS location.
A little story:
I own two houses. One in NC (10 years), one in CO (5 years).
The one in NC has decreased in value by 20% in those 10 years. And is even difficult to sell because of the lack of buyers.
The one in CO has increased in value by 60% in those 5 years. And would sell in days. Possibly above asking price & a cash offer.
If I was renting either house, it would cost significantly more than my mortgage payment.
My index funds (mid cap S&P 400) average around 12%/year.
So in order to rent AND save enough money to put into the stock market & earn greater returns, I'd have to get a lesser house, in a lesser area, with lesser schools.
And that's something I'm not willing to do. But if you don't have kids, or care about the size/quality/location of your domicile, then yeah it's a good idea.