Data Science for Economists
2026-03-01
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.
Motivation
Source: Deutsche Bank
Browse more products here: https://atlas.cid.harvard.edu/
| [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
Trade illustration
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 edgesLevel 0 – Simple
. . .
Level 1 – Directed
. . .
Level 2 – Weighted
Three representations of a toy trade network (USA, CHN, DEU): undirected/unweighted → directed → directed and weighted.
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 . . .Complete Graph
Star
Tree
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
Economic reading – The geodesic length tells you how many trade “hops” a Chilean export shock needs to reach Germany.
Walk (can revisit nodes) | Path (no repeated nodes) | Geodesic (shortest path, distance = 2)
walk | path | geodesic
How many paths from 3 to 1? Which is shortest?
Reading – Low diameter + high giant-component share imply shocks can spread globally; low density curbs redundancy.
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.
| 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.