NYTimes publishes a fantastic calculator [0] to help make this kind of rent vs. buy decision. It's not always that clear cut.
[0] https://www.nytimes.com/interactive/2024/upshot/buy-rent-cal...