Japanese Prime Minister Shinzo Abe and U.S. President Trump at Mar-a-Lago in Florida on Feb. 11. (Carlos Barria/Reuters)

If there’s anything that President Trump dislikes about certain trading partners, it’s their tendency to export more to the United States than they import. During the campaign, and for decades before, Trump criticized countries like China, Mexico, Germany and Japan for running large trade deficits with the United States.

Yet, Trump also has welcomed investment from these countries at every turn — especially Japan. In December, Trump wrapped his arm around the chief executive of SoftBank, a Japanese conglomerate, as the company announced a $50 billion investment in the United States. During a news conference with Trump last week, Japanese Prime Minister Shinzo Abe noted that Japan invested more than $150 billion into the United States last year.

For economists, these two positions represent something of a contradiction. When you look more closely at international flows of goods and money, you can see that foreign investment and trade deficits are two sides of the same coin.

“[When] Trump criticizes America’s trade deficits, but welcomes foreign investment, that’s a completely inconsistent position,” says Mark Perry, an economist at the American Enterprise Institute.

It may not be entirely intuitive, but the size of the trade deficit and the amount of foreign investment in the United States are directly related. As the graphic below shows, foreign investment in the United States and the trade deficit, in fact, are a mirror image of each other.

That’s simply because the global economy is a closed system: Every dollar that flows out has to flow back in at some point. Of course, from the time those dollars flow out of the country to buy foreign goods and back in as foreign investment, they can face a long and winding road, and create different winners and losers along the way.

That sounds complicated, but here’s a simple way to think about it.

For every dollar of goods that come into the country, the United States has to pay a dollar to a foreign seller. Foreigners generally use that currency in one of two ways, as economist Greg Mankiw has said. They can buy stuff in turn from American companies, boosting U.S. exports and reducing the trade deficit. Or they can invest dollars in American assets like Treasury notes, stocks or real estate — increasing both the U.S. trade deficit and foreign investment.

You can also turn the example around, and look at it from the perspective of investment demand first. When foreigners want to invest in the United States, first they need to buy dollars to do so. That greater demand for U.S. currency drives up the value of the dollar, which makes U.S. exports relatively more expensive on the global market, reduces exports and ends up expanding the trade deficit.

As the second example demonstrates, it’s also fair to say that one of the reasons the United States runs such a large trade deficit is that the economy is strong and attractive to foreign investors.

This doesn’t mean that foreign investment in the United States is bad — in fact, investment often creates jobs in the United States, which is presumably why Trump likes it. What it means that a trade deficit isn’t necessarily bad, either. Economists Gary Hufbauer and Euijin Jung have argued that the benefits of a trade deficit generally outweigh the costs when an economy is growing rapidly or experiencing high inflation, while the costs outweigh the benefits in times of recession or deflation.

What matters most is not necessarily whether a country has foreign investment or a trade deficit or surplus, but whether the economy is growing in a way that enriches its people, and if money is being invested in ways that makes a country more productive.

“To lament an American trade deficit is to lament the fact that foreigners are investing in America. And that seems rather odd to me,” says George Mason University economist Don Boudreaux.

Of course, foreign investment may not end up benefiting the same people that lost out from changes to trade. If a trade deficit results from a manufacturer shipping jobs overseas, for example, and then foreign investment comes back in the form of a Japanese hedge fund buying Apple stock, rather than a new Toyota plant in Ohio, many people might see that as a loss for the American worker.

It is true, as Trump trade adviser Peter Navarro said in an economic plan for the administration, that a larger trade deficit reduces the U.S. gross domestic product, a broad measure of economic activity. But as other economists have pointed out, that’s sometimes a matter of accounting, not necessarily of cause and effect.

GDP is defined as the value of goods and serviced produced in a country’s borders — so to calculate GDP, economists take everything that households consume, add in business investment, government spending and exports, and then subtract the value of imports, which are obviously not produced inside a country’s borders.

So imports reduce a country’s GDP in an accounting sense, but that doesn’t mean they necessarily cause GDP to be smaller, as economists from the University of Wisconsin-Madison and Tufts University said. The trade deficit and GDP are often driven by other factors. Let's say, for example, that Trump tax cuts cause the U.S. economy to boom. In that case, incomes could rise, and households could start to consume more imported goods as a result. In this case, the trade deficit might rise even as GDP does as well.

The economists argued that recent history bears this out: The U.S. trade deficit grew between 2002 and 2005, a time of strong growth, while it shrank during the Great Recession.

Navarro is not necessarily alone in his viewpoint — in fact, he is joined by some on the left. Josh Bivens, an economist at the Economic Policy Institute, has also argued that trade deficits hurt U.S. jobs.

“The logic is simple — exports boost demand for U.S. output while imports reduce demand for U.S. output. ... Trade deficits are the mirror image of capital inflows into the U.S. economy, and there are times when these capital inflows can reduce domestic interest rates and boost economic activity, providing an offset to the demand-drag caused by trade flows.” Yet, Bivens says, “today is not one of those times,” since interest rates in the United States are already so low that reducing them further would do very little to boost growth.

Still, many economists say they believe that the focus on the trade deficit as a kind of scorecard for U.S. performance is at best a diversion. Mankiw, who served under President George W. Bush, has called the trade deficit “a distraction.” Daniel Griswold, the former director of trade policy studies at the libertarian Cato Institute, told Congress than “no aspect of American trade is talked about more and understood less.”

That doesn’t mean that Trump has nothing to do on the economic front. Instead, many economists say the administration should shift its focus from the trade deficit to improving aspects of the economy that matter more for workers — like making sure U.S. companies are competing on an even playing field with competitors abroad, making smart investments to enhance the country’s productive capacity, ensuring the creation of good-paying jobs, and crafting policies to broadly share the gains of growth with those who are struggling most.

You might also like:

The places in America most exposed to a trade war

Is Trump keeping his economic promises? Here are eight ways to know.

Trump says making products in the U.S. is ‘gonna be cheaper.’ Economists disagree.