Chalk it up to the amazing powers of estrogen, a new study suggests.

Women are at increased risk for depression during periods of hormonal fluctuation, such as pregnancy, after childbirth, and at the end of their childbearing years. Now, a new study suggests that women exposed to more estrogen over their lifetime—including those who use hormonal birth control for many years—may be somewhat protected from that increased risk during and after menopause.

The study, published in the journal Menopause, may help explain why some women experience mood changes during these transitions while others breeze through, seemingly unaffected, say the study authors. Previous studies have suggested that reproductive hormones play a role in depression risk, but this is the first to look at specific sources of those hormones over time.

To do so, researchers analyzed data from 1,300 premenopausal women, ages 42 to 52 at the study’s start, who were followed for about 10 years. The women answered questions about their birth control use, the number of pregnancies they had, whether they breastfed, and when they first got their periods—all things that would influence the amount of estradiol (a form of estrogen) they were exposed to over the years.

Other studies have suggested that a woman’s lifetime estrogen exposure may be tied to various health outcomes later in life, including cognitive ability, bone fractures, and breast cancer risk. But estrogen is also involved in the production and metabolism of serotonin, a brain chemical that regulates mood—so the researchers thought it might also be linked to depression risk, as well.

Their hunch was right. Women who got their periods early and went through menopause late—meaning that they had more exposure to estrogen over their lifetimes—were less likely to report depressive symptoms during the transition to menopause and for up to 10 years after.

For each additional year between the start of menstruation and the onset of menopause, the women’s odds of depression decreased by 15%. That was true even when the researchers controlled for other potential risk factors, including demographics, behavioral and health conditions, and whether or not a woman experienced menopause side effects like hot flashes and night sweats.

Birth control use, which tends to raise a woman’s estrogen levels, was also protective: Longer use—measured as 5 or more years in the study—was associated with reduced depression risk. However, a woman’s history of pregnancies (which raise estrogen) and breastfeeding (which lower estrogen) had no association.

Lead author Wendy Marsh, MD, associate professor of psychiatry at the University of Massachusetts Medical School, says it’s not clear why some of these factors would affect depression risk and others would not. But she points out that a woman’s hormone levels can be affected by many other things—both within her body and in her external environment—and that more research is needed to determine how activities like breastfeeding or taking birth control pills really do affect those fluctuations. “I think a good deal of that remains a mystery,” she says.

The study authors also note that participants were not asked about oral contraceptive use beyond five years, while in reality many women stay on birth control pills for much longer than that. Because of this limitation, they say, their analysis may underestimate the pill’s protective power against depression later in life.

Still, because the study was observational, it could not show a cause-and-effect link between estrogen exposure and reduced depression risk. And while a potential reduction in depression odds may be one benefit of birth control, Dr. Marsh says women shouldn’t be making mental- or reproductive-health decisions based on it.

“I think if there’s concern about the risk of depression, there are clearer ways of staying in a good mood and taking care of one’s mental health,” she says. “Taking birth control wouldn’t be my first choice for preventing or treating depression.”

Other studies have also linked birth control pills to worse mood and quality of life, at least for some women. Dr. Marsh says these seemingly conflicting findings show the relationship between birth control and mood is complex, and still not well understood. “Maybe the women who stayed on birth control are the ones who didn’t have the negative effects, and so the reduced depression risk is self-selecting—we don’t really know,” she says.

Dr. Marsh also stresses that, even though hormonal transitions do raise the risk of depression, it’s still not something that most women experience during these times. “Most women do not get depressed during menopause,” she says. “But we’re delighted to be able to contribute to the understanding of why that increased risk does exist, and who it affects the most.”