Three essays on panel and factor models