Week 9 Homework Feedback: Alessia Canuto
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
- Function Definition: ✅
montecarlo_olsis correctly defined in a separate file with appropriate inputs and outputs. - DGP Logic: ✅ Correctly generates $x$ and $u$ inside the replication loop.
- OLS Logic: ✅ Uses
regresscorrectly to extract $\hat{\beta}_1$. - Execution: ✅ Loops over sample sizes $n \in {20, 50, 200}$ with $R=2000$.
- Visuals: ✅ Histograms plotted with normal density overlays.
- Statistics: ✅ Empirical mean and variance printed to command window.
- Interpretation: ✅ (Implied by the correct setup and visual comparison showing variance shrinking).
Part 2: Numerical Integration
- Utility Function: ✅ CRRA with $\gamma=2$ correctly defined.
- Trapezoidal Rule: ✅ Correctly uses
trapz. - 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) and3: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. - Grid Loop: ✅ Loops over the requested grid sizes.
- Visuals: ✅ Convergence plot clearly shows the two methods.
- Interpretation: ✅ The convergence plot effectively shows the results stabilizing.
Technical Implementation
- Organization: Correct.
montecarlo_olsis in a separate file. - Figures: Figures are saved correctly.
- Code Quality: Clean, readable, and well-commented.
Suggestions for Improvement
- 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.