(CNN) After a period of goodwill during the Obama years, the views of Mexicans toward the United States are souring.

According to a study released Thursday by the nonpartisan Pew Research Center, more Mexicans view the United States unfavorably than at any other time since 2002, when Pew started keeping track. They don't like President Donald Trump or his border wall proposal, and fewer believe strong economic ties are good for them, compared with two years ago.

But, as in most relationships, it's more complicated than it seems.

In a survey of 1,000 Mexicans from March to April, nearly two-thirds expressed an unfavorable opinion of their neighbor to the north. That's more than double the share in 2015, when 29% held a negative view of the US. And it represents a complete reversal of positions from 2015, when 66% of Mexicans held favorable views toward the US and 29% held unfavorable ones.

Opinions differ depending on age, income and education.

That may come as little surprise to anyone paying attention to Trump's rhetoric toward Mexico since the early days of his campaign, when he called some Mexicans in the United States "rapists" and pledged to build a "great wall" between the countries and make Mexico pay for it.

This erosion of goodwill corresponds with low approval of Trump. Just 5% of respondents said they had confidence in the American President to do the right thing regarding world affairs -- a steep decline from President Barack Obama's lowest rating among Mexicans, 38% in 2011, the report notes.

That doesn't mean Mexicans have written off the United States. Despite increased anti-American sentiment, 55% of respondents said moving to the United States offers a better life, an increase of 7% since 2015. And an overwhelming 85% of Mexicans said they were dissatisfied with the way things are in their own country.

Moreover, 33% of respondents said they would move to the United States if they could. This data point has remained relatively stable since 2009, even though more Mexicans left the United States than arrived between 2009 and 2014. What has changed is how young and old people answer the question: From 2015 to 2016, the same share of people ages 18 to 29 said they would move to the US; among people 50 and older, however, the number dropped significantly.

Something else to consider: Mexicans are less willing to live and work in the United States without authorization, a fact that calls to mind another key Trump administration priority. Only 13% of Mexicans said that they would do that, down from 20% two years ago.