The stock market taken as a whole has beaten the RE market -as a whole- over ANY 20 year period in history.
When this statement is uttered, it is with certain qualifications. For one thing, it does not take into account the tax deductions that the real estate market provides, and it also does not usually include the cash flow that a rental property provides. For the stock market to make a more equivalent analyses of returns for itself and the real estate market, it has to either account for the cash flow and tax deductions or eliminate the use of dividends in its returns calculations.