Capital-Market Imperfections and Countercyclical Markups: Theory and Evidence