top of page
Search

An Analysis of the U.S. Trade Balance Using Python

  • Writer: Sam Kovi
    Sam Kovi
  • May 25
  • 8 min read

The following post is my analysis of the data of the U.S. trade balance with tangible goods. The data for this analysis was sourced from the U.S. Census Bureau and can be found here. It is important to note that the data provided pertains solely to the goods trade and does not account for the value of services. As such, when referring to a “trade deficit”, I am discussing the trade deficit as it relates to goods. The U.S. maintains a trade surplus in the international service market. Because the magnitude of the U.S. goods trade deficit is significantly larger than the magnitude of the U.S. service trade surplus, the overall trade balance remains a deficit. Consequently, the trends described in this post apply to the total balance of trade, which includes both the goods and services market.

I performed my analysis using Python within Anaconda Navigator and Jupyter Notebook. Leveraging the pandas, numpy, matplotlib, and seaborn packages, I created visualizations and uncovered trends in U.S. trade patterns. The code used to analyze the U.S. balance of trade will be posted in a separate post.


Introduction

From precious gemstones on a ring to plastic children's toys, from life-saving pharmaceuticals to the computer this post was typed on, many consumer goods in the United States are imported. In the golden days of U.S. manufacturing, Americans primarily bought domestically produced goods. In the 21st century, this could not be farther from the reality, as consumers and producers alike purchase goods that are produced overseas. Trade, not just in the United States but also in the context of the world, has grown exponentially due to rapid technological advances: the internet allowed businesses to find international suppliers; refrigeration made it possible to ship food across oceans; cargo ships and airplanes revolutionized long-distance transportation. Further, the development of international trade organizations like the World Trade Organization (WTO) and the creation of regional trade blocs like USMCA, European Union and the Association of Southeast Asian Nations (ASEAN) have lowered trade regulations. The combination of each of these factors has spurred the exchange of goods across international borders. As this process continues, it becomes increasingly important to understand how trade influences a nation’s economic well-being.


Understanding Trade Balances

The trade balance of a nation is the difference between the value of goods it exports and the value of goods it imports. When the trade balance is positive, a country exports more than it imports and experiences a trade surplus; in contrast, a negative trade balance signifies a trade deficit. While many associate a trade deficit with a dip in the economy, the reality is that a deficit is neither harmful nor beneficial. Depending on the context, a trade deficit often accompanies high consumer demand, implying a healthy economy because consumers have sufficient discretionary income to spend on goods.

Although a small trade deficit in the short-term may not imply a country’s economic decline, a consistently increasing deficit may allude to problems with a country’s trade policy. In 2024, the deficit was 3.9 percent of current-dollar GDP, up from 3.3 percent in 2023. When the overall trade deficit becomes large relative to a country’s GDP, the value of the dollar depreciates as domestic consumers increase the supply of U.S. dollars by buying foreign goods. Currency depreciation reduces the purchasing power of domestic consumers for imported goods, which can lower the standard of living for those reliant on imports and potentially cause inflation. Another concern associated with trade deficits is the impact on American jobs. By importing more than it exports, the U.S. supports foreign industries over domestic ones, outsourcing American jobs to foreign nations to lower production costs. While the offshoring of jobs is inevitable, the issue is partially mitigated by the creation of high-skilled jobs in their place.

Trade balances are also affected by significant international events. Following the COVID-19 pandemic, the trade deficit continued to follow a historic trend of growth because domestic industries were unable to support consumer demand for household products due to lockdown restrictions and workplace regulations. By contrast, during domestic recessionary periods (as explained in more depth below), consumers experience depressed wages and incomes, thus decreasing their demand for goods. Simultaneously, foreigners view U.S. products as relatively cheaper and increase their demand for these goods. As a result, foreign imports decrease while U.S. exports increase, thereby lowering the trade deficit.


The Nature of U.S. Trade

When discussing the trade balance of the United States, its relationship with Mexico and China must be noted. Prior to 2023, China was the U.S.’s largest trading partner, with imports peaking in 2018 contributing to over 21% of U.S. goods imported for a total value of $539 billion USD. 

ree

Figure 1

However, in 2023, Mexico crossed China in terms of exports to the U.S., following a series of trade regulations and ensuing trade wars with China. As policymakers imposed tariffs on Chinese imports, domestic producers sought cheaper sources of materials elsewhere, turning to countries like Mexico — whose trade relationship was protected under the USMCA treaty — that had low-wage labor and a history of supply chain integration with the U.S. in order to protect low production costs. By 2024, the share of Chinese imports was reduced to just over 13%, whereas Mexico's share increased to over 15%.

ree

Figure 2

Also of note is the constant level of U.S. exports to major trading partners, like China, Mexico, and Vietnam. Since foreign purchases of  U.S. goods remain steady, even amidst domestic economic problems, U.S. exports are predominantly inelastic goods that have an unchanging demand regardless of economic conditions. These goods are essential to businesses in their production process, including products like mineral fuels, aircraft, and machinery. Additionally, the U.S.’s specialization in these industries permits a stable supply source to meet constant demand.

ree
ree
ree

Figure 3


The U.S. Trade Deficit

ree

Figure 4

Although the U.S. trade deficit started to rise after the oil crisis of the 1970s, the entrance of China into the WTO in 2001 has contributed to unprecedented levels of growth in the deficit. This trend is due to the lowered costs of goods accompanying WTO membership for China, incentivizing more consumers and businesses to purchase goods internationally. Yet, a deficit does not imply that a nation is losing money; it simply signifies that more goods are brought into the country than sent out of it. Empirically, during the 2008 recession, the deficit fell from over $800 billion USD to less than $500 billion USD after more than 15 years of steadily rising. After the recession, the deficit continued to rise, aligning with a period of economic growth. In 2021, the trade deficit (in goods only) crossed $1 trillion USD, with the number rapidly growing today. 

Part of the reason the U.S. experiences a deficit is because it imports a significant amount of raw materials and intermediate goods in order to produce high-value finished goods. These types of imports are often not found within the country or are too cost-inefficient to produce. As a result, it becomes more viable to import resources and dedicate labor and capital to other parts of the production process, creating the skilled jobs needed to produce high-value output. 


Tariffs

Following the election of President Trump in 2016, tariffs became a primary means to decrease the trade deficit, particularly with China, and develop American economic self-reliance. The most notable tariffs in the President’s first term were those imposed in 2018. Because the tariffs were disproportionately high on China in an effort to reduce reliance on Chinese manufacturing, the trade balance with China was also disproportionately affected, with the trade deficit decreasing by a notable 17.6%.

ree
ree

Figure 5

In contrast, the U.S. trade deficit with other trading partners like Ireland, Mexico, and Vietnam started to grow, showing an effort to diversify import sources and replace China’s low-cost products.

ree

Figure 6

Despite the tariffs, the net trade balance of the U.S. decreased only in the short-term. Whether the reduced impact of the tariffs can be explained by disrupted supply chains from the COVID-19 pandemic or changing trade relationships, it must be acknowledged that part of their diluted impact was because tariffs do not reduce trade; they simply shift import sources. As a result, American employment was not restored as intended because tariffs caused U.S. firms to find cheaper alternative import sources rather than turn to domestic sources. Unless there is a joint effort to develop American manufacturing and other critical industries alongside the use of tariffs, businesses will continue to choose inexpensive foreign exports over costly domestic goods. Indeed, from 2018 to 2019, the overall U.S. trade deficit fell by less than $50 billion USD; in 2020, the trade deficit rose slightly above 2018 levels.

ree

Figure 7

After 2020, the U.S. trade deficit saw annual increases of $60 billion USD, on average. A second round of tariffs in 2020 — six times higher than those imposed in 2018 — caused consumers and producers to import a significant quantity of foreign goods in advance of the higher costs, effectively raising the trade deficit. As a consequence of the post-pandemic economic boom in 2021, demand for goods increased as consumers became more willing to spend money in light of repealed COVID-19 regulations. The combination of both events caused the trade deficit to surge in 2021 and continue on that path.


Trade Surpluses

ree

Figure 8

While the U.S. has maintained a trade deficit since the 1970s, there are countries with which the balance of trade favors the U.S. In top countries that the U.S. holds a trade surplus with, including Brazil, Panama, the Dominican Republic, and Guatemala, the largest export is crude oil and petroleum. These Latin American countries are surrounded by the OPEC nation Venezuela, but choose to import oil from the U.S. to avoid conflicts with Venezuela’s unstable regime. Oil and other distilled products, valued at $320 billion USD in 2024,  makes up the largest export industry in the U.S. and thus is the most significant reason for trade surpluses with these nations.

On the other side of the spectrum are OECD countries like Australia, the United Kingdom, and Belgium. These nations hold a trade surplus with the U.S. due to their imports of valuable finished goods like aircraft, computer systems, and pharmaceuticals. The exception to this trend is the Netherlands, which maintains the largest trade surplus with the U.S., valued at approximately $57 billion USD. Upon the Russian invasion of Ukraine, oil imports from Ukraine became costly, causing the Netherlands to turn to the U.S. for alternate sources of fuel.


Conclusion

Analysis of the U.S. trade deficit reveals that a deficit does not directly imply expansionary or recessionary periods. Rather, conclusions about the economy from the balance of trade can only be drawn in conjunction with other economic indicators and contextual factors. As the nation enters a period of volatile trade policy, policymakers, consumers, and industry leaders should be aware of supply chain implications and prepare accordingly. Higher levels of trade barriers may start decreasing the trade deficit as companies choose domestic products over higher-cost foreign products. Whereas tariffs were historically targeted at one country, the current 2025 tariffs apply to all countries, preventing U.S. companies from seeking foreign alternatives and turning instead to domestic industries. However, in order to effectively reduce the trade deficit, the government should allocate revenue generated by tariffs to develop U.S. industries that were historically replaced by foreign exporters. With such a policy, the government can build economic resilience and provide alternate sources of goods for domestic firms, shifting the American economy from one that depends on foreign nations to one that is predominantly self-reliant.


Recent Posts

See All

Comments


bottom of page