Week 9 Homework Feedback: Alessia Canuto

Assignment: “Week 9: Monte Carlo OLS & Numerical Integration”

Overall Assessment

Grade: ✅ (Pass)

The submission implements the Monte Carlo simulation correctly, demonstrating the consistency of the OLS estimator. The numerical integration part applies the Trapezoidal rule correctly and attempts the manual Simpson’s rule, though there is a technical discrepancy regarding grid sizes (odd vs. even) for Simpson’s rule. The code is organized and produces the required outputs.

Task-by-Task Check

Part 1: Monte Carlo OLS

  1. Function Definition: ✅ montecarlo_ols is correctly defined in a separate file with appropriate inputs and outputs.
  2. DGP Logic: ✅ Correctly generates $x$ and $u$ inside the replication loop.
  3. OLS Logic: ✅ Uses regress correctly to extract $\hat{\beta}_1$.
  4. Execution: ✅ Loops over sample sizes $n \in {20, 50, 200}$ with $R=2000$.
  5. Visuals: ✅ Histograms plotted with normal density overlays.
  6. Statistics: ✅ Empirical mean and variance printed to command window.
  7. Interpretation: ✅ (Implied by the correct setup and visual comparison showing variance shrinking).

Part 2: Numerical Integration

  1. Utility Function: ✅ CRRA with $\gamma=2$ correctly defined.
  2. Trapezoidal Rule: ✅ Correctly uses trapz.
  3. Simpson’s Rule: ⚠️ Partial. You implemented the formula manually, which is great. However, standard Simpson’s rule requires an odd number of points (even number of intervals). With $N=50, 200, 1000$ (all even), your formula 2:2:end-1 (ends at 48 for N=50) and 3:2:end-2 (ends at 47 for N=50) actually misses the point at index $N-1$ (e.g., 49). The standard fix is to either use odd $N$ or drop the last point when $N$ is even.
  4. Grid Loop: ✅ Loops over the requested grid sizes.
  5. Visuals: ✅ Convergence plot clearly shows the two methods.
  6. Interpretation: ✅ The convergence plot effectively shows the results stabilizing.

Technical Implementation

  • Organization: Correct. montecarlo_ols is in a separate file.
  • Figures: Figures are saved correctly.
  • Code Quality: Clean, readable, and well-commented.

Suggestions for Improvement

  1. Simpson’s Rule Parity: When implementing Simpson’s rule manually, check if $N$ is even. If it is, you can’t apply the standard $1, 4, 2, 4, \dots, 1$ pattern to the whole array perfectly. A common trick is to use c(1:end-1) (making the grid length odd) or handle the last interval with the Trapezoidal rule.
    if mod(N,2) == 0
        % Use first N-1 points (odd number)
        vals = uc(1:end-1);
        % ... apply formula to vals ...
        % (Or add the last interval separately using Trapezoidal)
    else
        % Apply formula directly
    end
    

Summary

12/13 tasks correct. A strong performance. The manual implementation of Simpson’s rule is noted; attention to the odd/even grid requirement in numerical algorithms is recommended.