The summer that I was 24, my good friend Jen got married. She and I were very close, and I loved her dearly. But I actively dreaded her wedding for months.

My reasons for being grouchy about the wedding had nothing to do with my happiness for Jen. But she was marrying a great guy, and I was completely single with no romantic prospects. She had a ton of friends and family competing for an invitation to the big event; I had recently moved to a new city, and had exactly one (amazing) friend. And she was planning an epic, international honeymoon—while I hadn’t ever left the country.

It’s hard to admit, but I expected to have a horrible time at the wedding. I was certain that I would spend the entire time feeling sorry for myself and would leave feeling worse about my life—which, at the time, I wasn’t feeling too great about anyway.

It’s human nature to compare ourselves to others

Why would my friend’s good fortune cause me any stress? I didn’t want to marry her fiancé—though he’s a really nice guy, he’s way too into Chicago sports. I’m not the kind of person who needs a million friends; one or two good friends works really well for me. And although I hadn’t traveled much, I expected to go abroad eventually.

We’re all naturally driven to understand ourselves and our place in the world. According to psychologist Leon Festinger’s social comparison theory, our primary means of doing so is by ceaselessly asking, “How do I compare to those other guys?”

Think about it: What’s your best trait? I bet you said something like “I’m funny” or “I’m kind.” But funny or kind compared to whom? You wouldn’t think you were “funny” unless people laugh more at your jokes than at other people’s. You wouldn’t perceive yourself as “kind” if you haven’t had the experience of doing more for others than those around you. Even qualities like intelligence, which have “objective” measures like IQ tests, should be understood as highly comparative. To get into Mensa, for example, you have to score higher than 98% of the population. If you think about it, I bet you’ll discover that most of what you know about yourself is positioned against what you know about other people.

It matters less to us how we compare against people who are we perceive as very different from us. Since I thought of myself as a metropolitan, professionally-minded woman, it didn’t feel particularly relevant (or worrying) that most of the women I’d gone to high school with were already married with children at age 24.

We are, however, passionately interested in how we measure up to people we think we have a lot in common with. And unsurprisingly, we perceive our friends as very similar to us—particularly on issues that feel important. Because I was invested in work, travel, and feminism, for example, I had a group of girlfriends who were (for the most part) passionate about those same things.

We do most of our comparison against these close-association peer groups. And that’s why the wedding of a close friend is such a breeding ground for angst. What matters more than how worthy we are of love? My friend Jen, who I thought of as very similar to me, was clearly achieving a benchmark that felt well beyond my grasp. And this particular benchmark was one that—despite advances in feminism—women still feel a lot of pressure to attain by a certain age. No wonder I was a hot mess. The whole thing felt like a public pronouncement: “Your friend is worthy of lifelong love and devotion and you, Amanda, are not.”

If this sounds to you like a very primitive response, you are right. Humans are social creatures, and we seek status in large, mixed-sex groups as a matter of instinct. This trait comes from our primate ancestors, who organized this way to achieve safety.

But unlike our primate ancestors, we can actively shift our thoughts so that we can have happier lives—and have more fun at our friends’ weddings.

Thinking happier thoughts

If you’re having trouble feeling happy for an engaged friend, don’t beat yourself up. Remember, first of all, that it’s normal to compare yourself to your friends. The closer you are to that friend, the more prone you are to want the same things, and the more despair you may feel. It’s a natural response. And also it’s one you can manage once you realize how it operates.

First, think about what you have to be grateful for. Inherent in the social comparison theory is that people see themselves within hierarchies. If you feel like you’re on a distressingly low place on the social ladder, one solution is to turn your focus toward people who are even further behind. The idea here isn’t to feel smug about being better off—rather, it’s to feel empathy for the struggles faced by those who look to your own success with envy. This process will shift the focus away from what you don’t have in life, and create gratitude for what you do have.

Remember what you and your friend still have in common. It’s impossible to attend a wedding and completely ignore the fact that some people are getting married and you aren’t. The second tip from social comparison theory involves shifting the way you think about those who occupy the higher social status (i.e., your friend on her wedding day).

Rather than obsessing about things that you don’t have in common anymore, think about what you still share with each other. As you bring to mind your similarities—you both have English degrees, you both love Elvis Presley, you both refuse to drink beer—you’ll begin to recover your own confidence. Rather than seeing her success as a cause for despair, you’ll see that given how much you have in common, it’s very likely that you’ll eventually achieve the same status.

Shift your focus elsewhere. This final tip doesn’t come from social comparison theory, but from regular old cognitive psychology. Essentially, if you don’t want to think about something, distract yourself with a challenge. Give yourself a goal at the wedding, like “I’ll have conversations with 20 new people.” If the goal is difficult enough, your brain will turn away from the despair-inducing comparison and toward problem-solving.

Chin up

Keep in mind that the wedding is a single moment in time—and there is no reason to believe that the state of your life, at this particular moment, is any predictor of your long-term happiness.

Despite how left behind I felt at my friend’s lovely wedding all those years ago, it didn’t signify anything about how my life would turn out. I took a four-month international trip the very next year, met my husband in the year following my return, and had many friends at my own wedding four years after that. And as far as the present moment goes: Most people’s spirits can be lifted by following the advice of a song that tops many a wedding playlist: “Shut up and dance.”

Follow Amanda on Twitter @aj_crowell and visit her website, Powerful Peony. Learn how to write for Quartz Ideas. We welcome your comments at ideas@qz.com.