Holding period changes the answer
Buying carries large upfront and exit costs that are spread over the years you hold the property. A short stay can therefore favour renting even when the mortgage payment is close to the rent. A longer holding period can improve the buying case if ownership costs stay controlled and sufficient equity is built.
