Having hope may prevent people from engaging in risky behaviors, such as drinking alcohol, taking drugs, over-eating or gambling, a new study finds.

Researchers studied a concept called “relative deprivation,” or the feeling that other people have things better than you in life. They wanted to find out why only some people experiencing relative deprivation engage in risky behavior, HealthDay reports.

They studied volunteers who were questioned at the beginning of the study about their levels of relative deprivation and hope. The participants played gambling games that involved risk-taking and placing bets, with a chance to win money. The researchers found study participants who scored high for hopeful feelings were much less likely to take risks.

The study also found people with higher levels of hope had a lower risk of gambling problems, even in those with relative deprivation. The researchers said encouraging hope in people who are unhappy with their lives might protect them against harmful behaviors.