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.
- codes_week3 on Matlab online
- codes_week3.zip - Zip folder with all codes for week 3
- week3.m – Example script from lecture.
- gdp_quarterly.csv – CVS to be used in class and for the challenge.
- gdp_quarterly.xlsx – Excel file to be used in class.
- 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.
- week3_homework_starter.m – Starter file for homework.
- week3_challenge_solution.m – Solution file for in class challenge.
- week3_homework_solution_a.m – Solution file for homework using API.
- week3_homework_solution_b.m – Solution file for homework using CSV.
Homework submission
- Submit your homework here
- Please upload your homework as a single zip file. Access it’s now open with any email address! But remember to name your file with your full name and or student ID.
- The submission should include the .m file used to produce the results.
- You can modify you submission until the beginning of week 4.