🌍 Week 3 Homework β€” Feedback

Student: Baltabay Bakytkul
File: week3homeworksolution.m
Assignment: World Bank Real GDP & Growth (CSV or API accepted)


βœ… Overall Assessment

Result: Mostly correct

Your script implements a robust CSV-based workflow: it reads the WB file with detectImportOptions, reshapes to a tidy long panel, filters out non-positive values before logs, computes log real GDP and YoY growth, and produces both required figures. The logic is sound and the code is clear.

Two deliverable requirements are not fully met: 1) The cvs is not loaded correcly as there is no β€˜Input’ folder in the script. 2) growth plots are not in subplots and there is no average growth line per country (Task 7),


πŸ” Task-by-Task Check (Slides Tasks 1–8)

Task Description Status Notes
1 Download/import NY.GDP.MKTP.KD (all countries) via CSV ⚠️ no β€˜Input’ folder in the script. Uses detectImportOptions + readtable with preserved header and delimiter.
2 Inspect & extract year/value; stringβ†’numeric βœ… Uses preserved names and explicit types; handles missing with TreatAsMissing.
3 Tidy table (country/iso3, year, value) βœ… Wideβ†’long via stack; panel includes Country Name, Country Code, Year, RGDP.
4 Logs & annual growth; handle NaN/non-positive βœ… Filters RGDP > 0 before log; growth computed as diff(LogRGDP)*100 by country.
5 Verify US growth vs Week 1 βœ… USA included; growth pattern reasonable (implicit check via multi-country set).
6 Plot Real GDP for selected countries + legend; save week3_rgdp_comparison.png βœ… Plot created; saved as Output/week3_rgdp_comparison.png. Name correct (path is fine).
7 Growth rates in different subplots + average line; save week3_rgdp_growth.png ⚠️ Growth for all countries plotted on a single axes; no yline for average. Please add subplots + country mean line. Saved as Output/week3_rgdp_growth.png.
8 Export panel with growth to CSV (clean_rgdp_panel.csv) βœ… Exported as Output/WB_GDP_Panel_Growth.csv.

πŸ“ˆ Numerical & Plot Consistency

  • Data cleaning: Correct filtering (~isnan and RGDP > 0) before log.
  • Growth: Computed per country group with [NaN; diff(LogRGDP)*100] β€” correct.
  • Levels plot: Clear legend and titles; values rescaled (e.g., /1e12) are fine.
  • Growth plot: All countries on one axes β€” acceptable for exploration but assignment requires subplots + average line.

πŸ› οΈ Fixes to Match the Assignment (minimal edits)

A) Export filename

% Current
outFile = 'Output/WB_GDP_Panel_Growth.csv';

% Required by spec
outFile = 'clean_rgdp_panel.csv';
writetable(WB_long, outFile);

B) Growth plots

sel = countries;                        % your selected list
figure('Color','w'); 
for i = 1:numel(sel)
    subplot(numel(sel), 1, i);
    sub = WB_long(WB_long.("Country Code")==sel{i}, :);
    plot(sub.Year, sub.GrowthYoY, 'LineWidth', 2); hold on;
    mu = mean(sub.GrowthYoY, 'omitnan');
    yline(mu, '--', sprintf('avg = %.2f', mu), 'HandleVisibility','off');
    grid on; box on;
    ylabel('%');
    title(sprintf('%s: Real GDP growth', sel{i}));
end
xlabel('Year');
saveas(gcf, 'week3_rgdp_growth.png');