Essays on Market Imperfections in Macroeconomics and Finance