Essays on heterogeneity and macroeconomics