05. Networks

Data Science for Economists

Irene Iodice

2026-03-01

Why should I care?

  • Big picture: networks turn isolated data points into a map of economic interdependence.

  • Key insight: centrality and paths reveal who really drives trade, prices and growth.

  • Today’s skill: load a real network in R and compute its core stats.

Roadmap for today

  1. Concepts & data
  2. Metrics: walks, paths, diameter
  3. Centrality: degree, closeness, betweenness
  4. Null-model baseline
  5. Application: Economic Complexity

Motivation

Disruptions in the Automotive Industry

Source: Deutsche Bank

Chip shortage & global supply-chains

Browse more products here: https://atlas.cid.harvard.edu/

Smartphone GVC before vs after 2017

2009–12

2017–20

How has the network thinned?

Characteristics of the Supply Chain network
[2009:2012] [2013:2016] [2017:2020]
# of different countries 21 16 15
# of different Buyers 18 12 11
# of different Sellers 13 10 9
Number of supply links 224 154 130

Concepts & Representation

What is a network?

  1. A set of nodes (vertices)
  1. A set of edges (links) connecting pairs of nodes

Trade illustration

  • Nodes = countries
  • Edge \(i\rightarrow j\) if country \(i\) exports to \(j\)
  • Collect edges in an adjacency matrix \(A\) with \(A_{ij}=1\) when the flow exists

Creating a network in R

library(igraph)

# From an adjacency matrix
A <- matrix(c(0,1,1, 1,0,0, 1,0,0), nrow = 3,
            dimnames = list(c("USA","CHN","DEU"), c("USA","CHN","DEU")))
g <- graph_from_adjacency_matrix(A, mode = "undirected")

# From an edge list
edges <- data.frame(from = c("USA","USA","CHN"), to = c("CHN","DEU","DEU"))
g2 <- graph_from_data_frame(edges, directed = FALSE)

# Inspect
vcount(g)   # 3 nodes
ecount(g)   # 2 edges

From simple to richer graph structures

Level 0 – Simple

  • Undirected, unweighted
  • No self-loops (\(A_{ii}=0\))
  • Captures trade relationship (bilateral)

. . .

Level 1 – Directed

  • Order matters: \(A_{ij}\neq A_{ji}\)
  • Captures export flows

. . .

Level 2 – Weighted

  • Edge values = intensity (volume, tariff)
  • Can even be negative (cost/friction)

Three representations of a toy trade network (USA, CHN, DEU): undirected/unweighted → directed → directed and weighted.

Example of Directed Graph

library(igraph)
node_list <- tibble(id = 1:4)
edge_list <- tibble(from = c(1, 2, 2, 3, 4), to = c(2, 3, 4, 2, 1))
directed_g <- graph_from_data_frame(d = edge_list,
                   vertices = node_list, directed = TRUE)
get.adjacency(directed_g)
#> 4 x 4 sparse Matrix of class "dgCMatrix"
#>   1 2 3 4
#> 1 . 1 . .
#> 2 . . 1 1
#> 3 . 1 . .
#> 4 1 . . .

Example of Directed Graph (plot)

plot(directed_g, edge.arrow.size = 0.2)

Other types of graphs

Complete Graph

Star

Tree

Bipartite Network

Practical Corner: Bipartite Network

# generate a dataframe to represent all the edges of your bipartite network
d <- data.frame(
  country  = c("DEU", "DEU", "FRA", "FRA", "CAN", "CAN", "USA"),
  trade_agr = c("CETA", "EU", "EU", "CETA", "CETA", "USMCA", "USMCA")
)
# transform it into a graph
g <- graph_from_data_frame(d, directed = FALSE)
# define color and shape mappings to distinguish node types
V(g)$label <- V(g)$name
V(g)$type  <- 1
V(g)[name %in% d$trade_agr]$type <- 2
col   <- c("steelblue", "orange")
shape <- c("circle", "square")
plot(g,
     vertex.color = col[V(g)$type],
     vertex.shape = shape[V(g)$type])

Metrics

Walks, paths & geodesics

  1. Walk – Any ordered sequence of edges: CHL \(\rightarrow\) BRA \(\rightarrow\) DEU \(\rightarrow\) BRA
  1. Path – A walk with no repeated node: CHL \(\rightarrow\) BRA \(\rightarrow\) DEU
  1. Length – Number of edges in the path from \(i\) to \(j\) (above: 2)
  1. Geodesic – Shortest path between two nodes; its length is the graph distance, denoted \(\ell(i,j)\). For CHL–DEU the geodesic is CHL \(\rightarrow\) BRA \(\rightarrow\) DEU.

Economic reading – The geodesic length tells you how many trade “hops” a Chilean export shock needs to reach Germany.

Seeing the metrics (toy trade network)

Walk (can revisit nodes) | Path (no repeated nodes) | Geodesic (shortest path, distance = 2)

walk | path | geodesic

Test corner

How many paths from 3 to 1? Which is shortest?

Stats for graphs

igraph::all_simple_paths(directed_g, 3, 1)
#> [[1]]
#> + 3/4 vertices, named, from 2c34291:
#> [1] 3 2 1
#>
#> [[2]]
#> + 4/4 vertices, named, from 2c34291:
#> [1] 3 2 4 1

igraph::shortest_paths(directed_g, 3, 1)
#> $vpath
#> $vpath[[1]]
#> + 3/4 vertices, named, from 2c34291:
#> [1] 3 2 1

How connected is a trade network?

  1. Density (no self-loop) \[\delta = \frac{2m}{n(n-1)}\] where \(m\) = # edges, \(n\) = # nodes. [Guess for the trade network between countries?]
  1. Giant component size – Fraction of nodes in the largest connected piece. Ex. 94% of countries belong to one export web.
  1. Diameter \(\displaystyle \max_{i,j} \ell(i,j)\). “Farthest two countries need 6 hops.”
  1. Average path length \(\displaystyle \bar{\ell} = \frac{2}{n(n-1)} \sum_{i>j}\ell(i,j)\). Real trade: \(\bar{\ell}=3.1\)

Reading – Low diameter + high giant-component share imply shocks can spread globally; low density curbs redundancy.

Connectedness on our toy graph

Pentagon graph: CHL–USA–BRA–DEU–CHL, BRA–CHN. Five nodes, five edges.

Metric Value
Nodes \(n\) 5
Edges \(m\) 5
Density \(\delta\) 0.50
Giant component share 100%
Diameter 3
Avg. path length \(\bar{\ell}\) 1.9

All five countries sit in one component; any shock crosses the network in 3 hops or fewer.

Key Network Structures in Economics

Network Type Structure / Intuition Density Avg. Path Economic Context
Star (hub-and-spoke) One central hub connected to all others Low Very short Logistics, supply chains, platform economies
Core–periphery Dense central group + sparse outer nodes Medium Short to moderate Global trade hierarchy: developed vs. emerging
Modular (community) Dense internal clusters with few inter-cluster links Medium Moderate Regional trade blocs, innovation clusters
Scale-free Hubs dominate; many nodes with few links Low Very short Financial contagion, tech networks
Bipartite (countries–products) Two node types (e.g., exporters and goods) Structured Varies Economic complexity, RCA-based trade analysis

Different network shapes reflect different economic dynamics – efficiency, fragility, inequality, or specialization.

Application 1: Buyer–Supplier Network