The Impact of Endogenous Tax Treaties on Foreign Direct Investment: Theory and Evidence