Use the NYT Rent or Buy calculator. Most home made math don't account for the ton of fees/taxes/insurances and the time-value of money, and the exceptional returns of the SP500.
I have yet to find a single place that would have been worth it long term versus renting (Bay area, which is a VHCOL) while you do the correct math.