This paper analyses the evolution of attitudes towards immigration over the years 2002-2014, a period characterized by the rise of the economic crisis. Using data of the first 7 rounds of the European Social Survey, we estimate a random intercept model with two levels. By considering that individuals are naturally grouped into countries, this model takes into account the hierarchical structure of the data and allows us to evaluate the net impact of both contextual and individual factors on attitudes towards migrants. Results show that in almost all countries included in the study attitudes slightly improved during these years, even if this change was not homogeneous for all social categories. On one hand, after the beginning of the economic crisis, attitudes worsened for the individuals mostly affected by the recession, such as low skilled workers, because of an increased competition in the labour market between natives and immigrants. On the other hand, attitudes generally improved for people belonging to ethnic minorities and for the social categories that do not compete on the labour market, such as retirees.