There aren't many places with the access to as many high-paying jobs and the desirable walkability of NYC. That makes demand to live here high, and then we have on top of that artificial constraints on building new housing. Additionally, the suburbs outside of the city also have artificial constraints on building housing, and generally other cities that could become alternatives to NYC also have artificial constraints on building housing (and also don't build enough transit). All of that makes NYC more expensive and makes cities remotely like it (e.g. S.F.) more expensive.