Where It All Goes Down
Well, we don't get a lot in the way of setting in this poem. There are suggestions here and there (references to a gambling game, descriptions of interacting with common people and kings), but overall this poem doesn't really describe really any specific places.
Nonetheless, there are two places that, although not technically in the poem, are nevertheless a really big part of its identity. If you imagine a giant pot of soup cooking on the stove, the poem itself would be the soup, but the ingredients that gave the soup flavor would be the poem's historical background. To put it another way, there are two major settings that influenced the poem "If." You can't cook soup without a few ingredients, right?
The first bit of background would be late nineteenth-century South Africa. If you've read our "In a Nutshell" section, you know this poem was inspired by the exploits of a dude named Sir Leander Starr Jameson, who led a failed invasion into an area of South Africa called the Transvaal. The Jameson raid was part of an unauthorized attempt to gain control of the Transvaal, and its recently discovered gold and diamond deposits. At the time, South Africa wasn't South Africa. It was a collection of colonies and territories—some British, others run by the descendants of the original Dutch settlers (called "Boers"), such as the Transvaal. (Check out a map of 1895 South Africa right here.)
The British really wanted control of the whole area, especially some of the Boer-controlled areas. For their part, the Boers were fed up with British intervention and began moving away from the British, only to see the British come after them. The 1890s in South Africa, then, was a time of conflict, yet another battleground between European powers that was nowhere near European soil. The British and the Boers would eventually fight a few wars, the second of which, called the Second Boer War, ultimately resulted in the British annexation of most of the area.
"If" also very much belongs to the late Victorian period, an era known for its relative uptightness and conservatism. If you take a look at this site, you can get an idea of what we mean by that. Read more about the Victorian period here and more about Queen Victoria herself right here.
The Victorian period was also the great age of British Imperialism. And by great, we do mean great. By 1900, Great Britain controlled nearly a quarter of the world's land, and governed almost 400 million people (some more strictly than others). Australia, New Zealand, large chunks of Asia (primarily India and Pakistan), and even larger chunks of Africa (Nigeria, South Africa, Sudan, Kenya, Malawi, and others)—not to mention Canada—were all part of the Empire.
The British saw themselves as partaking in a civilizing mission on the one hand (non-Europeans were less evolved, and couldn't govern themselves, the theory went), but also as improving their own country. British expansion gave the country greater accesses to resources unavailable back home (tea and sugar, for example) and opened up other opportunities (such as trade routes). While we could go on for days about the British Empire, for now you can read more about it here if you like.
So, while the actual setting of Kipling's poem is not well-defined for us, the historical and cultural settings in which "If" appeared are pretty clear: Britain was branching out all over the world, and it took a certain kind of personality to lead that charge. What kind, you might ask? Well, look no further than the instructions provided by the poem itself.