# Heteroskedasticity and HC1 / 异方差与稳健标准误 Entirely simulated data: seed 42, n=500; x~Uniform(-2,2), z~N(0,1), x/z independent; y=1+2x+(0.3+1.2|x|)z. Observations are independent; the error has zero conditional mean, but its variance depends on x. No research files or accounts are used. ## Offline rerun / 离线复做 Extract into a new directory and keep a reference copy of results/. From the package root: ```sh python -m venv .venv # macOS/Linux source .venv/bin/activate # Windows: .venv\Scripts\activate python -m pip install -r requirements.txt python analyze.py ``` Installing dependencies accesses a software repository; analysis itself is offline and overwrites named files under this package's results/ directory. Python 3.11.11/macOS was used. scipy supplies Student-t quantiles/p-values; NumPy computes coefficients and covariance matrices explicitly. Stata can independently use the bundled simulated CSV without Python or third-party Stata commands. In a new licensed Stata session, set the working directory to this package root: ```stata do analysis.do ``` clear all clears that session's memory; replace overwrites stata.log and stata-estimates.csv in this practice folder. Save existing work first. Stata 19.5/macOS tested, version 17 declared; Windows hardware untested. Check ROBUST_SE_COMPLETED / ROBUST_STATA_COMPLETED. Both methods use the same 500 observations and coefficients, with conventional versus HC1 covariance; Stata vce(robust) matches the Python HC1 calculation. Compare coefficient/SE/interval/p-value columns against the reference files; cross-check.json records THIS published run, not certification of your new run. Changing the seed is an exercise, not a reason to search for a desired p-value: ```sh python analyze.py --seed 7 --output-dir exercise-seed-7 ``` Stata reads results/simulated-data.csv by default; a different Python output directory does not automatically redirect Stata to that alternate dataset. To cross-check a new seed, use a separate copy of the entire package and regenerate its default results/ before running Stata. ## Interpretation / 解释 HC1=n/(n-k)*(X'X)^(-1)*sum(x_i*x_i'*e_i²)*(X'X)^(-1), with k=2 including the intercept. Conventional covariance uses residual MSE times (X'X)^(-1). Intervals and p-values use t(n-k) as a reference, not an exact finite-sample guarantee under heteroskedasticity. This run's slope is significant by both reference calculations; the case does not manufacture a significance reversal. Robust SEs do not change coefficients or repair endogeneity, omitted variables, clustering or serial correlation. HC1 SEs need not always be larger. 代码只生成模拟数据;普通与HC1比较只改变协方差计算,不改样本或系数。区间采用t参考,不保证异方差有限样本覆盖率。HC1不能修复内生性、组内相关或时间相关,也不一定使所有标准误变大。 Files: analyze.py, requirements.txt, analysis.do, results/simulated-data.csv, estimates.csv, result.json, analysis.log, SVG/PNG; actual stata.log and stata-estimates.csv; cross-check.json; this README. No third-party executable or original research data is bundled.