Andrew Leigh look at this question in a paper, "Does the World Economy Swing National Elections?", in the Oxford Bulletin of Economics and Statistics, Vol. 72, No. 2. The abstract reads,
Do voters reward national leaders who are more competent economic managers, or merely those who happen to be in power when the world economy booms? Using data from 268 democratic elections held between 1978 and 1999, I compare the effect of world growth (luck) and national growth relative to world growth (competence). Both matter, but the effect of luck is larger than the effect of competence. Voters are more likely to reward competence in countries that are richer and better educated; and there is some suggestive evidence that media penetration rates affect the returns to luck and competence.The paper provides evidence that voters commit systematic attribution errors when casting their ballots – tending to oust their national leaders when the world economy slumps and retain them when it booms. Across a wide range of countries, voters appear to behave only quasi-rationally. Is anyone really surprised by that? Note that any given individual voter has little incentive to try to distinguish a lucky government from a skilful one since we all know that elections are almost never decided by a single vote, and so each voter would be right to conclude that her vote is highly unlikely to make a difference.
What factors are associated with voters rewarding competence and luck? In countries with a richer and better educated population, voters are better able to parse out competence from luck in deciding whether to re-elect their national leaders. Leigh also find suggestive evidence that the media affects the returns to luck and competence, though these effects seem to differ across media types. Countries with high newspaper circulation have voters better able to distinguish luck from skill. Radio does not help, and television makes things worse. Well, given the standard of economic reporting on New Zealand television that last result doesn't exactly surprise me.