In the us, you're also writing off the portion of your mortgage payment that is composed of Interest on your taxes. This effectively amounts to a 20 to 40% reduction in the interest portion of the payment - which, particularly in the first few years of a mortgage lifespan constitutes a large fraction of it.
In a few more years after that, inflation will have started to tilt the advantage substantially in favor of the mortgage over renting, as the latter can freely recalibrate to the market while the former is locked in at the time of signing.
The only downsides for mortgage versus rent are ongoing property taxes and upkeep, which are highly variable from one case to the next, but nowhere approach the cost of paying an equivalent amount of rent. And of course you have to discount equity as well.