Download real-world datasets (WDI, UCDP, V-Dem, FRED, WVS) and create publication-quality figures for lecture slides. Use when user says 'download data', 'WDI', 'World Bank', 'UCDP', 'make a graph from data', 'data visualization', 'integrate data', or wants real empirical figures in slides.
Download real-world datasets from major repositories and create publication-quality figures ready for Beamer slide integration.
# Option 1: wbgapi (recommended — clean API)
pip install wbgapi
import wbgapi as wb
# GDP per capita
data = wb.data.DataFrame('NY.GDP.PCAP.CD', economy=['DEU', 'USA', 'CHN'], time=range(2000, 2024))
# Military expenditure (% of GDP)
data = wb.data.DataFrame('MS.MIL.XPND.GD.ZS', time=range(1990, 2024))
# Tax revenue (% of GDP) — fiscal capacity
data = wb.data.DataFrame('GC.TAX.TOTL.GD.ZS', time=range(2000, 2024))
# Option 2: pandas-datareader
from pandas_datareader import wb as wbdr
data = wbdr.download(indicator='NY.GDP.PCAP.CD', country=['DE', 'US', 'CN'], start=2000, end=2023)
# UCDP GED (Georeferenced Event Dataset)
import pandas as pd
url = "https://ucdp.uu.se/downloads/ged/ged241-csv.zip"
ged = pd.read_csv(url, compression='zip')
# UCDP/PRIO Armed Conflict Dataset
url = "https://ucdp.uu.se/downloads/ucdpprio/ucdp-prio-acd-241-csv.zip"
acd = pd.read_csv(url, compression='zip')
# Key variables: year, type_of_violence, conflict_name, country, best_est (fatalities)
# V-Dem v14
url = "https://v-dem.net/data/dataset-version-14/"
# Download Country-Year: V-Dem Full+Others
# Key indices: v2x_polyarchy, v2x_liberal, v2x_partipdem, v2x_egaldem
from pandas_datareader.data import DataReader
oil = DataReader('DCOILWTICO', 'fred', '2000-01-01', '2024-12-31') # WTI crude
Read the lecture .qmd to understand:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams.update({
'font.size': 14,
'axes.labelsize': 16,
'axes.titlesize': 18,
'xtick.labelsize': 12,
'ytick.labelsize': 12,
'legend.fontsize': 12,
'figure.figsize': (10, 6),
'figure.dpi': 150,
})
# USG color palette
USGBLUE = (0/255, 51/255, 102/255)
USGRED = (153/255, 0/255, 0/255)
HIGHLIGHT = (204/255, 51/255, 0/255)
USGGRAY = (102/255, 102/255, 102/255)
Requirements:
plt.figtext(0.5, 0.01, 'Source: ...', ha='center', fontsize=10, color='gray')plt.style.use('seaborn-v0_8-whitegrid') or similarProduce a .qmd snippet ready for insertion:
## [Slide Title]
```{=latex}
\begin{center}
\includegraphics[width=0.95\textwidth]{data_figures/FILENAME.pdf}
\end{center}
\source{Data: World Bank WDI (2024); Author's calculations}
### Phase 5: Save
- Figure PDF → `Lectures/slides/data_figures/FILENAME.pdf`
- Python script → `Lectures/slides/data_figures/generate_FILENAME.py`
- Both the figure AND the generation script (for reproducibility)
## Example Use Cases by Lecture
| Lecture | Data Need | Source | Figure Type |
|---------|-----------|--------|-------------|
| 01 Foundations | Conflict trends 1946-2023 | UCDP ACD | Line chart |
| 03 Economic Shocks | Commodity prices vs conflict onset | WDI + UCDP | Scatter/panel |
| 04 Resources | Oil prices and civil war | FRED + UCDP | Time series |
| 05 Displacement | Top refugee-hosting countries | UNHCR | Bar chart |
| 06 State Capacity | Tax/GDP vs growth | WDI | Scatter |
| 07 Geoeconomics | Trade openness trends | WDI | Line chart |
| 08 Sanctions | Russia trade flows pre/post 2014/2022 | Comtrade | Event study |
| 09 Trade Policy | US-China tariff timeline | WTO/USTR | Timeline |
| 10 Energy | Critical mineral concentration | USGS | Bar/map |
## Fallback: Synthetic Data
When real data download fails (no network, API down, data too large):
1. Create realistic synthetic data based on known stylized facts
2. Label clearly as "Stylized illustration based on [Source] patterns"
3. Use the same figure styling and output format
4. Save generation script for later real-data replacement
## Integration with Replication Exercises
When creating data figures, also produce a **student starter script**:
```python
# Student Exercise: Replicate Figure X from Lecture Y
#
# Task: Download WDI data on [indicator] and create a figure showing [pattern]
#
# Step 1: Install wbgapi (pip install wbgapi)
# Step 2: Download data for countries [...] for years [...]
# Step 3: Create a scatter plot of [X] vs [Y]
# Step 4: Add a trend line and discuss what you observe
#
# Your code here:
import wbgapi as wb
import matplotlib.pyplot as plt
# TODO: Download data
# data = wb.data.DataFrame(...)
# TODO: Create figure
# plt.figure(figsize=(10, 6))
# ...
Save student scripts to Replications/exercises/