Earlier this year, the BBC sparked an international discussion about pay equity following the release of an embarrassing report on the salaries of its staff. Men at the organization were being paid 9.3 percent more than women on average. What’s more, only a third of the BBC’s highest-paid on-air stars were women, and some 500 female employees earned less than men who had similar roles.

Stories like this are becoming familiar, as more evidence piles up that women are less likely to be promoted than men and earn less on average. We see it not just in journalism but in tech and countless other fields — including medicine, a profession that relies mostly on women. Studies have shown that female doctors earn up to 27 percent less than male doctors in the same specialty.

But it can be difficult to suss out just how much of these gaps can be explained by bias alone versus differences in rank or productivity.

Now a working paper out of Harvard University offers new insight on that question. And it’s a damning indictment of gender bias in the workplace.

For the paper, economics PhD candidate Heather Sarsons came up with an ingenious study design to tease out exactly how much more women were punished at work compared to men when you held other factors like their positions or performance stable. Sarsons got Medicare data on referrals by doctors to surgeons, and then looked at what happened to doctors’ referral rates after one of their patients died during a surgery. Would the doctor continue sending patients to that surgeon?

It turns out the surgeon’s gender — more than his or her performance — massively swayed that decision. The referring doctors judged female surgeons who had bad patient outcomes much more harshly than male surgeons, and that judgment determined whether they’d send their patients to the surgeon later.

“[Doctors] increase their referrals more to a male surgeon than to a female surgeon after a good patient outcome,” Sarsons wrote, “but lower their referrals more to a female surgeon than a male surgeon after a bad outcome.”

Referrals dropped by 54 percent after a patient died at the hands of a female surgeon, but when it was a male surgeon whose patient died, there was only a small stagnation in the referrals the surgeon received from the doctor.

What’s more, a good patient outcome (i.e., an unanticipated survival) led doctors to become more optimistic about a male surgeon’s ability, again using referral volumes after a surgery as the proxy for the doctors’ views of the surgeons’ talent. The same wasn’t true for female doctors.

“I was surprised at how persistent [the effect] was,” Sarsons told Vox. She looked at data for up to a year and a half after a bad event, and found female surgeons were consistently receiving fewer referrals. “Women were being punished more for a bad event,” she added.

Perhaps most disturbingly, she also uncovered that the poor performance of one female surgeon later shaped how all female surgeons in the same specialty were viewed by referring physicians afterward. Sarsons found this happening in the context of new referrals for doctors, when they didn’t have long relationships with the surgeons. Again, there were no similar “spillovers” to male surgeons after a negative experience with one new surgeon.

“[Doctors] become less likely to form new referral connections with women after a bad experience with one female surgeon,” Sarsons wrote. “A bad experience with one male surgeon does not affect [doctors’] behavior toward other men.”

Harvard Medical School professor Anupam Bapu Jena, who has studied the gender wage gaps but was not involved in this paper, said he thought the study was “extraordinarily clever.” Given how difficult it can be to sort out where bias may arise in the work context, Sarsons helped pinpoint it: Gender-biased reactions were the strongest when a doctor was beginning to refer his or her patients and had little other information on which to judge the surgeon. In those cases, a person’s gender became a shorthand for their competence.

It’s not a shocker that we can be less forgiving of women and harder on them when they falter. And the study shows we respond more to positive information about a man in the workplace, and more to negative information about a woman. The result is that for the exact same errors as men, women’s careers and earnings might take a much harder hit. (In this case, they didn’t get as many referrals as male doctors — which suggests they undertook fewer cases and earned less.)

The bias Sarsons uncovered might just explain “these gaps,” she said, “and why we see these differences: women being promoted less frequently than men, women [not having] as many raises, women being under-rewarded for their successes.”