ESSAYS ON MACROECONOMIC POLICY WITH HETEROGENEOUS AGENTS