• Economics Data Analysis
  • I PREFACE
  • Welcome to CDI – Economics Data Analysis
    • Why Economics Data Analysis in CDI?
    • Who this guide is for
    • What you’ll learn
    • How to use this guide
    • Why it matters
    • Transition to Q&A
  • II FOUNDATIONAL Q&A
  • 1 How do you obtain real-world economics datasets?
    • 1.1 Explanation
    • 1.2 World Bank wbdata example
    • 1.3 Python Code
  • 2 How do I compare GDP trends across EAC countries and the USA?
    • 2.1 Explanation
    • 2.2 SQL Approach
  • 3 How do you inspect the GDP data you just loaded?
    • 3.1 Explanation
    • 3.2 SQL/MySQL Code
    • 3.3 Python Code — robust connection (works with XAMPP on macOS)
    • 3.4 Install (once)
  • 4 How do you query a country’s GDP trend over time?
    • 4.1 Explanation
    • 4.2 SQL/MySQL Code
    • 4.3 Python Code
  • 5 How do you compare GDP trends across EAC countries on a single plot?
    • 5.1 Explanation
    • 5.2 SQL/MySQL Code
    • 5.3 Python Code
    • 5.4 ✅ Learning Outcome
    • 5.5 🧠 Takeaway
  • 6 Which EAC country has the most stable vs most volatile GDP growth?
    • 6.1 Explanation
    • 6.2 SQL/MySQL Code
    • 6.3 Python Code
    • 6.4 Learning Outcome
    • 6.5 Takeaway
  • 7 How does Econometrics relate to Machine Learning?
    • 7.1 Explanation
    • 7.2 Example with GDP Growth
    • 7.3 Python Code (Econometrics vs ML)
    • 7.4 Learning Outcome
    • 7.5 Takeaway
  • 8 How do I analyze GDP growth using Econometrics vs Machine Learning?
    • 8.1 Explanation
    • 8.2 SQL/MySQL Code (Econometrics style)
  • 9 How do I create and load a new table for GDP growth factors in MySQL?
    • 9.1 Explanation
    • 9.2 SQL/MySQL Code
    • 9.3 Learning Outcome
    • 9.4 Takeaway
  • 10 How do I visualize GDP levels and GDP growth factors?
    • 10.1 Explanation
    • 10.2 SQL/MySQL Code
    • 10.3 Python Code
  • III REAL WORLD Q&A
  • Explore More Guides

Economics Data Analysis Q&A

Q&A 2 How do I compare GDP trends across EAC countries and the USA?

2.1 Explanation

A line chart makes it easy to compare the GDP growth of multiple countries over time. Since GDP is measured in current US$, the USA’s scale will dwarf EAC economies — but this highlights the contrast in economic size.

⸻

2.2 SQL Approach

If you have this dataset loaded into MySQL (table: gdp_data), you can query Kenya’s GDP trend like:

Note Country Code

MariaDB [cdi_economics]> SELECT DISTINCT country FROM gdp_wdi ORDER BY country;
+---------+
| country |
+---------+
| BI      |
| CD      |
| KE      |
| RW      |
| SO      |
| SS      |
| TZ      |
| UG      |
| US      |
+---------+
9 rows in set (0.032 sec)
-- Remove the old table completely
DROP TABLE IF EXISTS gdp_wdi;
CREATE DATABASE cdi_economics;
USE cdi_economics;

CREATE TABLE gdp_wdi (
  country CHAR(3),
  year INT,
  gdp_usd_current DOUBLE
);

LOAD DATA LOCAL INFILE '/Users/tmbmacbookair/Dropbox/GITHUB_REPOs/cdi-economics/data/gdp_wdi_EAC_USA_2000_2024.csv'
INTO TABLE gdp_wdi
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(country, year, gdp_usd_current);

-- Query Kenya's GDP trend
SELECT year, gdp_usd_current
FROM gdp_wdi
WHERE country = 'KE'
ORDER BY year;