Week 3
Week 3 – Data Input/Output & Plotting
Learning Outcomes By the end of this week, students will be able to:
- Understand and use different data types in MATLAB.
- Import and export data between MATLAB and common formats (CSV, Excel, MAT).
- Organize data using arrays, tables, and timetables.
- Perform simple data cleaning and transformations.
- Produce basic 2D plots and customise them.
- Save figures and outputs for reports.
Suggested Readings
- Frain, MATLAB for Economics and Econometrics, Ch. 3 (Data I/O) & Ch. 5 (Plotting).
- MatlabCheatSheet.pdf - plotting.
In-Class Activities
- Import data using
- online sources: API vs direct URL.
- CSV/Excel files.
- Convert imported data into MATLAB tables and timetables.
- Diagnose missing values and handle them (rmmissing, fillmissing).
- Compute year-on-year GDP growth from quarterly data.
- Plot GDP levels and YoY growth with:
- Titles, axis labels, and legends.
- Automatic colour + varying line styles for multiple series.
- Save outputs:
- Cleaned dataset to .mat and .csv.
- Plots as .png and .fig.
Homework / Practice
- Download real GDP (constant prices, 2015=100) for all available countries from the World Bank (via API or direct CSV).
- Build a panel dataset in MATLAB and convert to a table.
- Compute for each country:
- Log of GDP
- YoY growth rates
- Select some countries of your choice
- Produce and save plots:
- Real GDP levels on the same plot with different colours/styles +legend.
- Each country YoY growth rate on a different subplot plus a line showing the average growth rate over the sample.
- Export the cleaned panel dataset and figures.
Files
- Slides Week 3 – Slides from lecture.
- week3.m – Example script from lecture.
- week3_load_FRED_data.m – Example script that loads US NGDP data from FRED.
- week3_load_WB_data.m Example script that loads World Bank data.
- week3_challenge_starter.m – Starter file for in class challenge.
- gdp_quarterly_missing.csv – CVS to be used in class challenge.
- gdp_quarterly.csv – CVS to be used in class challenge.