That's "The Gostak and the Doshes" by Miles J. Breuer, M.D., which was also the answer to the question Short story where a character moves through dimensions via mental exercises; first published in Amazing Stories, March 1930; full text available at Wikisource. There's a review at Alex Kasman's Mathematical Fiction site.
I expect this is from an anthology from about 1950.
If the anthology was that old, it was probably Groff Conklin's Science Fiction Adventures in Dimension.
It is set on Earth, in the U.S., I believe.
Earth, for sure; the U.S., probably. The location of the narrator's college in not given, but note the American references in his description of the parallel-world city:
What in particular shall I say about the city? It might have been any one of a couple of hundred American cities. Only it wasn't. The electric street cars, except for their bright green color, were perfect; they might have been brought over bodily from Oshkosh or Tulsa. The ten-cent stores with gold letters on their signs; drug-stores with soft drinks; a mad, scrambling stock-exchange; the blaring sign of an advertising dentist; brilliant entrances to motion-picture theaters, were all there. The beauty-shops did wonders to the women's heads, excelling our own by a good deal, if I am any judge; and at that time I had nothing more important on my mind than to speculate on that question. Newsboys bawled the Evening Sun, and the Morning Gale in whose curious, flat type I could read accounts of legislative doings, murders and divorces, quite as fluently as I could in my own Tribune at home. Strangeness and unfamiliarity had bothered me a good deal on a trip to Quebec a couple of years ago; but they were not noticeable here in the t dimension.
The key part of plot is by walking with his eyes closed down a college path and visualizing very hard that the slope is the reverse of what it "really" is (slightly up instead of slightly down, or vice versa, I don't recall), the protagonist is instantaneously shifted into a parallel world
"The success of this experiment in changing from the z to the t coordinate has depended largely upon my lucky discovery of a favorable location. It is just as, when you want the moon to ride the tree tops successfully, there have to be favorable features in the topography or it won't work. The edge of this building and that little walk between the two rows of Norway poplars seems to be an angle between planes in the z and t dimensions. It seems to slope downwards, does it not?—Now walk from here to the end and imagine yourself going upwards. That is all. Instead of feeling this building behind and above you, conceive it as behind and below. Just as on your ride by moonlight, you must tell yourself that the moon is not moving while the trees ride by—Can you do that? Go ahead then." He spoke in a confident tone, as though he knew exactly what would happen.
Half credulous, half wondering. I walked slowly out of the door; I noticed that Woleshensky settled himself down to the table with a pad and a pencil to some kind of study, and forgot me before I had finished turning around. I looked curiously at the familiar wall of the building and the still more familiar poplar walk, expecting to see some strange scenery, some unknown view from another world. But there were the same old bricks and trees that I had known so long; though my disturbed and wondering frame of mind endowed them with a sudden strangeness and unwontedness. Things I had known for some years, they were, yet so powerfully had Woleshensky's arguments impressed me that I already fancied myself in a different universe. According to the conception of relativity, objects of the x, y, z universe ought to look different when viewed from the x, y, t universe.
Strange to say, I had no difficulty at all in imagining myself as going upwards on my stroll along the slope. I told myself that the building was behind and below me, and indeed it seemed real that it was that way. I walked some distance along the little avenue of poplars, which seemed familiar enough in all its details; though after a few minutes it struck me that the avenue seemed rather long. In fact, it was much longer than I had ever known it to be before.
With a queer Alice-in-Wonderland feeling I noted it stretching way on ahead of me. Then I looked back.
I gasped in astonishment. The building was indeed below me. I looked down upon it from the top of an elevation. The astonishment of that realization had barely broken over me, when I admitted that there was a building down there; but what building? Not the new Morton Hall, at least. It was a long, three-story brick building, quite resembling Morton Hall, but it was not the same. And on beyond there were trees with buildings among them; but it was not the campus that I knew.
I paused in a kind of panic. What was I to do now? Here I was in a strange place. How I had gotten there I had no idea. What ought I do about it? Where should I go? How was I to get back? Odd that I had neglected the precaution of how to get back. I surmised that I must be on the t dimension. Stupid blunder on my part, neglecting to find out how to get back.
a parallel world which is technologically very similar
Breathlessly eager to find out what sort of a world I had gotten into, I walked with him to his home. And I may state at the outset that if I had found everything upside down and outlandishly bizarre, I should have been far less amazed and astonished than I was. For, from the walk that first evening from Professor Viben's office along several blocks of residence street to his solid and respectable home, through all of my goings about the town and country during the years that I remained in the t-dimensional world, I found people and things thoroughly ordinary and familiar. They looked and acted as we do, and their homes and goods looked like ours. I cannot possibly imagine a world and a people that could be more similar to ours without actually being the same. It was months before I got over the idea that I had merely wandered into an unfamiliar part of my own city. Only the actual experience of wide travel and much sight-seeing, and the knowledge that there was no such extensive English-speaking country on the world that I knew, convinced me that I must be on some other world, doubtless in the t dimension.
but much more restrictive of thought.
My apprehensions were quite correct. With my usual success at self-control over a seething interior, I coolly walked to the draft office and informed them that I did not believe in their cause and could not see my way to fight for it. Evidently they had suspected something of that sort already, for they had the irons on my wrists before I had hardly done with my speech.
"Period of emergency," said a beefy tyrant at the desk; "no time for stringing out a civil trial. Courtmartial!"
He said it at me vindictively, and the guards jostled me roughly down the corridor; even they resented my attitude. The court-martial was already waiting for me. From the time I walked out of the lecture at the church I had been under secret surveillance; and they knew my attitude thoroughly. That is the first thing the president of the court informed me.
My trial was short. I was informed that I had no valid reason for objecting. Objectors because of religion, because of nationality, and similar reasons, were readily understood; a jail sentence to the end of the war was their usual fate. But I admitted that I had no intrinsic objection to fighting; I merely jeered at their holy cause. That was treason unpardonable.
"Sentenced to be shot at sunrise!" the president of the court announced.
The happy ending is an escape via desperately reversing the visualization.
Then it all suddenly popped into my head; how I had gotten here by changing my coordinates, insisting to myself that I was going upwards. Just like making the moon stop and making the trees ride, when you are out riding at night. Now I was going upwards. In my own world, in the z dimension, this same poplar was down the slope.
"It's downwards!" I insisted to myself. I shut my eyes, and imagined the building behind and above me. With my eyes shut, it did seem downwards. I walked for a long time before opening them. Then I opened them and looked around.
I was at the end of the avenue of poplars. I was surprised. The avenue seemed short. Somehow it had become shortened; I had not expected to reach the end so soon. And where were the guards in olive uniform? There were none.
I turned around and looked back. The slope extended on backwards above me. Indeed I had walked downwards. There we no guards, and the fresh, new building was on the hill behind me.
This may well have been in an anthology including a story about a man trapped in a large Möbius strip.
I don't know about that; haven't identified the Möbius strip story.
It may or may not have been a reaction against McCarthyism.
The story was originally published in 1930, long before McCarthyism.