Sigh. I do understand leverage. Perhaps I phrased it wrong above. You can purchase shares with "other people's money" as described in your quote, hence you can leverage.
Sigh, not as well as you think.
Yes, you can use other people's money to buy shares. But not with the same ease and to the same extent as you can on a home mortgage.
In addition to this you have the opportunity cost of having a 400k loan. While you have a debt of 400k on the mortgage you will have to forgo other investment opportunities. This is because as your debt level rises, and hence your leverage rises, your risk as an borrower increases and institutions are less likely to lend you money.
Credit scores don't work like that. When you take out a mortgage and establish a history of paying it, your credit rating goes up, not down.
Realestate is good for some people and not good for others. If you move around a lot then realestate has risks that other asset classes do not, shares being one of those classes.
If you are leveraged on the purchase of shares, your risk is much greater. There are lots of protections for home buyers that don't apply to purchases of shares. That's why I suggested buying a house, living there for a while, then leasing it when you want to move. Also, you should factor in the rent that you are not paying.
I think that, if you think you can use a few thousand dollars to buy a few hundred thousand dollars worth of shares, you are likely to be disappointed. Of course, today, the amount of leverage that I got on my house purchase is not possible or, very unlikely.
As you point out, though, house purchases are unlikely to work as a short-term investment (although there are people who flip houses for profit). Run the numbers assuming the same yearly increase in value over a 5-year period.