# OLS sampling / OLS 抽样分布教学 All observations are simulated. No original research data, account, network API or paper material is used. Model: y = 1 + 2x + error; x and error are independent standard normals, observations independent. Seed 42. 500 fresh samples for each of n=30 and n=300; the displayed single n=30 sample is also the first draw in the n=30 sampling group. The smaller samples are not prefixes of the larger samples. ## 运行 / Run 解压到新目录,先保留一份原 results/ 作参考。下列命令从包根目录执行。安装依赖会访问软件源;分析本身离线,不安装软件或读取其他数据。默认只覆写此包 results/ 下同名输出。 Extract into a fresh directory and retain a reference copy of results/. Run from the package root. Dependency installation accesses a package repository; analysis itself is offline. Default output overwrites only named files under this package's results/ directory. ```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 ``` 本次使用 macOS / Python 3.11.11,依赖见 requirements.txt;Windows 真机复做未覆盖。 Check the completion marker OLS_SAMPLING_COMPLETED. single-sample.csv has 30 observations, sampling-slopes.csv has 1,000 coefficient rows (500 per sample size), and result.json reports mean, sample SD (ddof=1), and empirical quantiles. Compare CSV numbers and summary fields, not image bytes: SVG IDs/timestamps can vary. ## 练习 / Exercises ```sh python analyze.py --seed 7 --output-dir exercise-seed-7 python analyze.py --repetitions 2000 --output-dir exercise-more-draws ``` 先改变种子,保持生成模型和样本量不变,比较一次估计。然后增加重复次数,比较模拟分布是否更平滑。增加重复次数与增加每次样本量是不同操作;不改 seed/repetitions 时,同一依赖环境应重现数值。 Change seed first while keeping the generating model and sample sizes fixed. Then increase repetitions and inspect the simulated distribution. More repetitions are not more observations in each regression. Unchanged parameters and the same dependency environment reproduce numerical output. ## 解释 / Interpretation - 单次斜率不必等于真值 2;这次 n=300 的分布更集中,不能说每个大样本估计都更接近真值。 - 表里的 2.5% / 97.5% 是模拟斜率的经验分位数,不是某一次回归的 95% 置信区间。 - 样本量增加不能修复内生性、测量错误或错误模型;本例只解释这个独立、同方差、零条件均值模型下的抽样波动。 - A single slope need not equal 2. The n=300 distribution is narrower in this run; not every larger sample must yield a closer estimate. - Empirical 2.5% / 97.5% slope quantiles are not a confidence interval for one regression. - Larger n does not repair endogeneity, measurement error or model misspecification. This example assumes independent observations and a correctly specified homoskedastic model. Files: analyze.py, requirements.txt, this README, results/single-sample.csv, sampling-slopes.csv, result.json, analysis.log, ols-sampling.png and .svg. The program is adapted from Marx Max's already public self-written econometrics classroom example; no third-party code or research data is bundled. Public figures/CSV are actual standalone simulation outputs, not evidence of a model-run or classroom learning effect.