Real Estate potentially has two components of profit, the increase in value, and the ongoing returns, similar to a stock appreciating and its dividends.
It's possible to buy both badly, and in the case of stocks, there are studies that show the typical investor lags the market by many percent.
Real estate is not a homogeneous asset class. A $200K house renting for $1,000 is a far different investment than a $100K 3 family renting for $2,000 total rents. Both exist depending on the part of the country you are in.
If you simply divide the price to the rent you get either 16.7X or 4.2X. This is an oversimplification, and of course, interest rates will push these numbers in one direction or another. It's safe to say that at any given time, the ratio can help determine if home prices are too high, a bargain, or somewhere in between.
As one article suggests, the median price tracks inflation pretty closely. And I'd add, that median home prices would track median income long term.
To circle back, yes, real estate can be a good investment if you buy right, find good tenants, and are willing to put in the time.
Note: Buying to rent and buying to live in are not always the same economic decision. The home buyer will very often buy a larger house than they should, and turn their own 'profit' into a loss. e.g. A buyer who would otherwise be advised to buy the $150K house instead of renting is talked into a bigger house by the real estate agent, the bank, the spouse. The extra cost of the $225K house is the 1/3 more cost of repair, utilities, interest, etc. It's identical to needing a 1000 sq ft apartment, but grabbing one that's 1500 sq ft for the view.