Esther Cepeda says she is much happier than before she started writing a gratitude journal. (Greg “Fritz”Blakey / FRITZ PHOTOGRAPHICS INTERNATIONAL)

CHICAGO — Two years ago, anxiety was keeping me up at night, threatening to spiral out of control. Meanwhile, my husband with his easy confidence — never seeing a rain cloud without a silver lining, always constructing the best possible scenario when confronted with a set of hazy details — slept like a baby. I decided I wanted that kind of peace in my life.

So I decided to brainwash myself.

I pulled out all the stops: I meditated daily (a crazy-hard practice). I programmed my iPhone to send me automated texts throughout the day reminding me to not worry. I rewrote my personal history, casting it in a fortunate light. I started holding a pencil with my teeth because I read somewhere that it mimics the act of smiling and lifts your mood.

Then Janice Kaplan’s book “The Gratitude Diaries: How a Year Looking on the Bright Side Can Transform Your Life” came out, promising that by just being thankful one could crowd out negative thoughts.

I started keeping — and it pains me to say this because it’s soooo “Oprah Winfrey Show” and completely out of character — a gratitude journal. The idea was that just jotting down a few very quick, context-free thoughts every day to engage in the physical act of being thankful would accumulate over time and keep me focused on the positive.

The brainwashing worked.

The silver bullet was the act of writing. Looking back at two years of these notes, I can feel the relief and gratitude wash over me. For instance, an entry from November 2015: “I’m so, so thankful for not having to get another root canal.”

I like this one, too, from a cold December 2016 day when my fuel gauge told me I had zero miles left in my tank: “I’m so thankful I made it to the gas station.”

Other days, I was just thrilled that my son had a good day at school or that my puppy hadn’t chewed up my shoes or that I’d found a dollar bill on my walk — all good stuff that’s easy to forget unless you actively recall and transcribe it at the end of the day.

Today, I’m at least 10 times as happy as I was when I started. And although all the little hacks helped to some degree, it was the tangibility of writing out good things that made the magic.

This magic is replicable, and it demonstrably works.

Building upon prior research concluding that psychological interventions like self-affirmation can improve academic performance in vulnerable groups, researchers from Stanford University gave positive-writing exercises to Latino and African American middle-school students in two geographically different areas of the United States.

The students were asked to choose two to three core values that were personally important — such as relationships, creativity or humor — and then write a few sentences about why they were important. The exercises took place during stressful times, over the course of a year in middle school, including at the beginning of the year and right before exams. (Students in a control group did a neutral-writing assignment.)

Researchers then tracked the students (African Americans through college enrollment and Latinos through high school enrollment) using official school records.

The results, published in the Proceedings of the National Academy of Sciences, found that of the students who participated in writing about their values, Latino students were more likely to have entered a college-readiness track than a remedial one near the transition to high school. They also took more-challenging courses, such as a college-readiness elective, and were less likely to be placed in remediation.

African American students were more likely to enroll in college seven to nine years later, including relatively more selective colleges.

The authors make clear that the intervention was specifically designed for students feeling under threat because of stereotypes but who were at middle-class schools, not at schools with low levels of infrastructure and resources. So, positive writing probably is not a cure-all for what ails students at the lowest end of the spectrum of need.

That said, when it comes to overcoming challenges that have roots in our insecurities, the power that we have to lift ourselves up is strong. It’s a power we should harness for ourselves and teach to our kids so it can be deployed when we most need it.

Cepeda is a nationally syndicated columnist based in Chicago.