🌍 Week 3 Homework β€” Feedback

Student: Davide Magnini
Assignment: World Bank Real GDP & Growth (CSV version)


⚠️ Overall Assessment

Result: ⚠️ Partially correct

The student’s code correctly attempts to load and process the World Bank dataset once the directory is changed manually, but it fails during the import stage and cannot proceed to compute logs or growth rates.
The main structure follows the expected flow but is not reproducible and contains errors that prevent successful execution.


πŸ” Main Issues (compared to the reference CSV solution)

  1. Non-reproducible directory change
    • The script uses a hard-coded cd to access the data file, which makes the code machine-dependent.
    • Fix (as in the reference solution): Use relative paths and avoid changing the working directory:
      % Reference approach
      opts = detectImportOptions('WB-WDI_time_series.csv');
      T = readtable('WB-WDI_time_series.csv', opts);
      

      This keeps the code portable and consistent with the Week 3 template.

  2. Column names not read correctly
    • All columns appear as Var1, Var2, … because the header line was not recognized.
    • In the reference solution, this is handled by MATLAB’s detectImportOptions, which automatically detects the variable names and data types.
    • Fix:
      opts = detectImportOptions('WB-WDI_time_series.csv');
      T = readtable('WB-WDI_time_series.csv', opts);
      

      After this step, the variables should include CountryName, CountryCode, IndicatorName, IndicatorCode, and year columns.

  3. Indexing error (split_name{4})
    • The error
      Index exceeds the number of array elements. Index must not exceed 1.
      

      occurs because split_name has fewer elements than expected.

    • The reference solution does not extract country names from the filename β€” it reads them directly from the dataset (CountryName column).
    • Fix (align with reference):
      % Extract country names directly
      country_list = unique(T.CountryName);
      
  4. Data cleaning and transformation missing
    • After loading, the student script does not proceed to reshape or clean the data.
    • In the reference, the following steps are implemented:
      • Convert wide data to long format (year/value per country).
      • Drop missing or non-positive values before taking logs.
      • Compute log and annual growth rate:
        wb_table.log_gdp = log(wb_table.value);
        wb_table.growth  = [NaN; diff(wb_table.log_gdp)] * 100;
        
    • These steps are essential to obtain correct growth rates.
  5. Plots and outputs missing
    • Figures (week3_rgdp_comparison.png, week3_rgdp_growth.png) and the CSV export (clean_rgdp_panel.csv) are not created because the script stops at the import error.

πŸ“Š Deliverables Check

Deliverable Status Comment
clean_rgdp_panel.csv ❌ Not generated
week3_rgdp_comparison.png ❌ Not generated
week3_rgdp_growth.png ❌ Not generated
Log and growth computation ❌ Not implemented due to import failure

πŸ’¬ Style & Clarity

  • The code layout is clean and easy to follow.
  • However, missing semicolons cause unnecessary Command Window output.
  • The script name is still week3_homework_starter.m β€” it should be renamed to week3_homework_solution.m before submission.

βœ… Suggested Fixes (based on the reference CSV solution)

  1. Load the data properly using import options ```matlab opts = detectImportOptions(β€˜WB-WDI_time_series.csv’); T = readtable(β€˜WB-WDI_time_series.csv’, opts);