[I]t is to be noted that it is common to name a droll fellow, regarded as typical of his country, after some favorite article of food, as E[nglish] Jack-pudding, G[erman] Hanswurst ("Jack Sausage"), F[rench] Jean Farine ("Jack Flour"). [Century Dictionary, 1902, entry for "macaroni"]Originally it seems to have been applied insultingly to the Dutch, especially freebooters, before they turned around and slapped it on the English. A less-likely theory (attested by 1832) is that it represents some southern New England Algonquian language mangling of English. In English a term of contempt (1750s) before its use as a general term for "native of New England" (1765); during the American Revolution it became a disparaging British word for all American natives or inhabitants. Contrasted with southerner by 1828. Shortened form Yank in reference to "an American" first recorded 1778. Latin-American form Yanqui attested in English by 1914 (in Mexican Spanish by 1835).
The rule observed in this country is, that the man who receives that name [Yankee] must come from some part north of him who gives it. To compensate us for giving each other nicknames, John Bull "lumps us all together," and calls us all Yankees. ["Who is a Yankee?" Massachusetts Spy, June 6, 1827]