Essays in Macroeconomics with Micro Frictions and Heterogeneity