This doctoral dissertation has for main focus the analysis of the optimal level of public debt in an economy where agents face idiosyncratic risk, credit constraints and can only partially insure against future risks because of incomplete markets. It extends the existing literature with three original contributions. The first chapter investigates the optimal level of public debt in presence of macroeconomic fluctuations. The second chapter models a stylized economy with entrepreneurial and working households and determines the impact on the optimal level of public debt. The third and last chapter revisits the optimal level of public debt in a time-consistent economy where the government does not have access to a commitment technology. Throu...