However, there may be an occasion when it is worth considering the counteroffer. If you have allowed your frustrations to build up without voicing it to your employer, you may find you're a disgruntled employee for no reason. A discussion about the issues causing you to resign could result in a resolution that annuls the need to move on to a new opportunity, and in this situation, you may opt to stay.
But even better, you should raise these concerns prior to resigning - that way you will quickly find out if they can be resolved or if they are in fact a solid reason for seeking alternative employment.
While a counteroffer is flattering, it is important to remember the reasons you started pursuing a new job opportunity in the first place, and stay true to this - accepting a counteroffer will only be a short-term cure for a long-term problem.