I think the difference in real estate and the stock market is the automated long term nature of real estate investing. More money and effort goes into saving up for real estate and searching for the right house. And once you make the investment you don't want to sell any time soon. Since it's not all that easy and straight forward. Real estate automatically means investing
The stock market is easier it can be done faster and people tend to trade instead of invest. And trading is not investing. If you put as much effort into finding the right companies to invest in and have the same time frame , i.e. sell almost never and simply expand you will get there as well.
Due to the psychology behind trading and the easy in and out of the markets people tend to make great errors and panic in times of turmoil. And dump their portfolio. Houses are not dumped that easily.
If you have a simply investing strategy , much the same as investing in real estate is a simply enough strategy you will be fine in the stock market as well.