The average Silicon Valley engineer is compensated roughly $200,000 a year, and gets to work in offices with perks like daily catered lunch, on-site yoga, and life coaching.

Still, for many people, particularly if you are a woman or underrepresented minority, these aren’t fun places to work. Take hard-charging Uber, which has seen a slew of executives flee the company after a female employee detailed a horrific saga of harassment and discrimination in February. Or Ellen Pao, who sued her former employer, the male-dominated venture capital firm Kleiner Perkins, after alleging that she was denied promotion because of her gender and cut out of business dinners because male colleagues felt that having women there would “kill the buzz.” Or tech giants Oracle and Google, which were recently sued by the Department of Labor for systematically underpaying female and minority workers.

A new study of turnover in the tech sector goes beyond these isolated incidents and lawsuits and takes a stab at a persistent question: How widespread are these problems?

The study, by the Oakland, California-based non-profit Kapor Center for Social Impact and Harris Poll, asked a nationally-representative sample of 2,000 adults who had voluntarily left a tech job in the last three years why they chose to abandon their cushy workplaces. Were they enticed by a better opportunity? Did they decide to take time off to care for children? Did they desire a shorter commute?

The answers the “tech leavers” gave were eyebrow-raising in that they suggest the extent to which feelings of mistreatment drive people to leave even the most elite jobs. They also show the way the same workplace can be a vastly different experience depending on a person’s background.

Overwhelmingly, workers of all backgrounds cited “unfairness or mistreatment” within the work environment as the most common reason for leaving. Thirty-seven percent said it was as “major factor” in their decision to quit. Unfair treatment was cited twice as often as being recruited elsewhere.

The study also compared workers in tech to other industries, and found that people cite unfairness as a reason to leave a job in tech more frequently than people in other industries (42 percent compared to 32 percent).

Not surprisingly, the study found that workplace experiences differ dramatically by race, gender, and sexual orientation.

The Kapor Center found that men of color were the most likely to quit because of unfairness. Forty percent of black and Latino men — both groups are underrepresented in the tech industry — left their jobs for that reason. Nearly a quarter of underrepresented men and women of color said they had experienced racial stereotyping, twice the rate of white and Asian men and women. Black and Latino women were more likely than any other group to say they were passed over for a promotion.

To be sure, turnover in Silicon Valley is very low overall, and people who leave companies are more likely to have an axe to grind than those who stay. That is to say, the results of a study of people who leave may not reflect how most women and underrepresented minorities who work in tech feel. But if people from certain groups are quitting in higher numbers than people from other groups, it’s worth understanding why, the authors said. They added that further study may be needed on why blacks and Latinos have more negative experiences at work than whites and Asians in the tech industry.

The study’s authors said they examined retention because efforts to increase diversity through hiring has gotten a lot of attention in recent years. Technology companies are now spending hundreds of millions of dollars a year to increase their dismal diversity numbers; so far they’ve had limited results.

Women represent 25 percent of tech employees though they comprise half the population; blacks and Latinos make up 30 percent of the population but roughly 15 percent of tech employees. Among the top Silicon Valley companies, black and Latino employees are only 3 to 5 percent of the workforce.

Hiring is only one half of the equation, the authors argued. If technology companies don’t make substantial efforts to understand how people feel once they are in the workplace, their hiring efforts will be canceled out by turnover.

“Put simply, the diversity numbers may not be changing at least in part because tech companies have become a revolving door for underrepresented groups,” the authors wrote.