This commit is contained in:
cattom committed 2026-10-23 15:52:32 +08:00
1 parent 5d77d1b7eb
commit 3e43896a11
20 files changed
+1155

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.
+23
View File
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content="Week 7 计量经济学:随机扰动项与残差,98 条家庭消费明细的 Stata 回归、数据核对与复现报告。"><title>Week 7|家庭消费回归分析</title><style>
:root{color-scheme:light;--ink:#182c40;--muted:#5c6d7b;--accent:#146b72;--line:#dce5e9;--paper:#fff;--bg:#f3f6f7}*{box-sizing:border-box}html{scroll-behavior:smooth;scroll-padding-top:24px}body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.85 "Microsoft YaHei","PingFang SC",system-ui,sans-serif}a{color:var(--accent);text-underline-offset:3px}header{background:#143044;color:white;padding:56px 32px 44px}.hero{max-width:1080px;margin:auto}.eyebrow{letter-spacing:3px;color:#a6d7d9;font-size:12px;font-weight:700}h1{font-size:clamp(28px,4.4vw,46px);line-height:1.4;margin:14px 0 16px;letter-spacing:-1px}.subhead{color:#c7d7e0;max-width:760px;margin:0}.metrics{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-top:30px}.metric{border-top:1px solid #547080;padding:14px 0 0}.metric span{display:block;font-size:12px;color:#bacfd9}.metric strong{font-size:27px;font-weight:600;font-variant-numeric:tabular-nums}.layout{max-width:1240px;margin:auto;display:grid;grid-template-columns:200px minmax(0,1fr);gap:38px;padding:34px 28px 70px}nav{position:sticky;top:24px;align-self:start;font-size:13px}nav .nav-title{color:var(--muted);margin:0 0 12px;font-size:11px;letter-spacing:2px}nav a{display:block;text-decoration:none;color:var(--muted);padding:8px 12px;border-left:2px solid var(--line)}nav a:hover,nav a:focus{border-color:var(--accent);color:var(--accent);background:#e7eff0}main{min-width:0;background:var(--paper);padding:30px 36px 42px;border:1px solid var(--line);border-radius:8px}h2{font-size:23px;line-height:1.5;margin:42px 0 18px;padding-top:24px;border-top:1px solid var(--line);scroll-margin-top:24px}p{margin:15px 0}strong{font-weight:650}.equation{font-family:"Cambria Math","Microsoft YaHei",serif;font-size:19px;line-height:1.8;background:#edf5f5;color:#154d58;border-left:3px solid #329097;padding:17px 22px;margin:22px 0;overflow-wrap:anywhere}.note,.warning{padding:17px 20px;background:#f0f5f8;border-radius:4px}.warning{background:#fff6e7;border-left:3px solid #c18a29}.table-wrap{overflow-x:auto;margin:20px 0;border:1px solid var(--line);border-radius:5px}table{width:100%;border-collapse:collapse;font-size:13px;font-variant-numeric:tabular-nums}th{text-align:left;background:#edf2f5;color:#304b5e;font-weight:600;white-space:nowrap}td,th{padding:11px 13px;border-bottom:1px solid var(--line);vertical-align:top}tbody tr:last-child td{border-bottom:0}tbody tr:nth-child(even){background:#fafcfc}td:first-child{white-space:nowrap}code{font:0.88em/1.6 Consolas,"Microsoft YaHei",monospace;background:#edf2f5;padding:2px 5px;border-radius:3px;overflow-wrap:anywhere}pre{background:#182d3d;color:#e5eff5;padding:20px;overflow-x:auto;border-radius:6px;font-size:13px;line-height:1.8}pre code{background:none;color:inherit;padding:0;white-space:pre}figure{margin:24px 0}img{display:block;width:100%;height:auto;border-radius:4px}figcaption{color:var(--muted);text-align:center;font-size:12px;margin-top:9px}details{padding:15px 18px;border:1px solid var(--line);border-radius:5px;margin:20px 0}summary{cursor:pointer;color:var(--accent);font-size:14px}details img{margin-top:20px}.prediction{background:#eff7f6;padding:20px 24px;border:1px solid #cbe3df;border-radius:6px;margin:24px 0}.prediction label{font-weight:600}.prediction-values{display:flex;justify-content:space-between;gap:16px;flex-wrap:wrap;margin-top:12px;font-size:14px}.prediction output{font-variant-numeric:tabular-nums}.prediction input{width:100%;margin:18px 0 0;accent-color:var(--accent)}.prediction p{font-size:12px;color:var(--muted);margin:6px 0 0}footer{text-align:center;padding:0 24px 36px;font-size:12px;color:var(--muted)}@media(max-width:980px){.layout{grid-template-columns:1fr;gap:18px;padding:22px 18px}nav{position:static;display:flex;flex-wrap:wrap;gap:4px}nav .nav-title{display:none}nav a{border-left:0;padding:5px 10px}main{padding:22px 25px}.metrics{gap:10px}.metric strong{font-size:22px}}@media(max-width:560px){header{padding:32px 22px}.metrics{grid-template-columns:repeat(2,1fr)}main{padding:18px 16px}.layout{padding:14px 10px 36px}h2{font-size:20px}.equation{font-size:17px;padding:14px}body{font-size:15px}td,th{padding:9px 10px}}@media print{body{background:white;color:black;font-size:10pt}header{background:white;color:black;padding:12px 0}.hero{max-width:none}.eyebrow,.subhead{color:#444}h1{font-size:24pt}.metric span,.metric strong{color:#222}.layout{display:block;padding:0;max-width:none}nav,.prediction,details,footer{display:none}main{border:0;padding:0}h2{break-after:avoid;margin-top:24px;padding-top:12px}table{font-size:9pt}tr,figure{break-inside:avoid}a{color:inherit}pre{white-space:pre-wrap;color:black;background:#f4f4f4}pre code{white-space:pre-wrap}.table-wrap{overflow:visible}}
</style></head>
<body><header><div class="hero"><div class="eyebrow">ECONOMETRICS · WEEK 07 · 2026.10.23</div><h1>随机扰动、残差<br>与家庭消费回归</h1><p class="subhead">从概念区分到数据核对,用 Stata 估计收入与消费的线性关系。完整呈现原始数据问题、拟合结果与可复现过程。</p><div class="metrics"><div class="metric"><span>有效家庭记录</span><strong>98</strong></div><div class="metric"><span>收入组数</span><strong>10</strong></div><div class="metric"><span>收入系数</span><strong>0.7288</strong></div><div class="metric"><span>拟合优度 R²</span><strong>0.9307</strong></div></div></div></header><div class="layout"><nav aria-label="报告目录"><p class="nav-title">CONTENTS / 目录</p><a href="#concepts">1. 随机扰动项与残差项</a><a href="#data">2. 数据整理与原表核对</a><a href="#results">3. 回归设定、过程与估计结果</a><a href="#figure">4. 仿照示例图作图与残差解释</a><a href="#reproduce">5. 复现方法与 Stata 指令</a><a href="#files">6. 交付文件索引</a><a href="#sources">7. 方法依据与来源</a></nav><main><p class="">研究日期:2026 年 10 月 23 日。数据:Eg2_1_1/Eg2_1_1.xlsx(Sheet1)。实际执行软件:Stata/SE 15.1,路径 D:/Stata15/StataSE-64.exe;脚本使用 version 15.0 语法。</p><p class="">本研究使用原表 98 条家庭消费明细,估计每月可支配收入与每月消费支出的线性关系,并参照给定图片完成 Stata 作图。所有金额单位均为元。</p><div class="equation">Ŷ = 22.9309 + 0.728799X;n = 98;R² = 0.930666</div><h2 id="concepts">1. 随机扰动项与残差项</h2><p class=""><strong>随机扰动项</strong> uᵢ 是实际观测值与真实总体条件均值之间的偏差。写作 Yᵢ = m(Xᵢ) + uᵢ,其中 m(Xᵢ) = E(Yᵢ | Xᵢ)。它反映给定收入后,家庭偏好、人口规模、其他未纳入因素及随机变化造成的消费差异。真实总体条件均值通常未知,因此 uᵢ 通常不可直接观测。</p><div class="equation">uᵢ = Yᵢ − E(Yᵢ | Xᵢ);若 m(Xᵢ) = β₀ + β₁Xᵢ,则 uᵢ = Yᵢ − β₀ − β₁Xᵢ。</div><p class=""><strong>残差项</strong> eᵢ 是实际观测值与拟合值之间的偏差。它在估计回归系数后可以计算,是对相应随机扰动的估计。</p><div class="equation">eᵢ = Yᵢ − Ŷᵢ = Yᵢ − β̂₀ − β̂₁Xᵢ。</div><div class="table-wrap"><table><thead><tr><th scope="col">比较维度</th><th scope="col">随机扰动项 uᵢ</th><th scope="col">残差项 eᵢ</th></tr></thead><tbody><tr><td>参照对象</td><td>真实总体回归函数 E(Y | X)</td><td>利用数据估计的回归函数 Ŷ</td></tr><tr><td>参数</td><td>真实且通常未知的 β₀、β₁</td><td>可由数据算出的 β̂₀、β̂₁</td></tr><tr><td>能否直接计算</td><td>通常不能</td><td>拟合后可以</td></tr><tr><td>零均值性质</td><td>以真实条件均值定义时 E(u | X) = 0;设定线性模型时需相应条件成立</td><td>含截距 OLS 的样本残差满足 Σeᵢ = 0(数值计算有舍入误差)</td></tr><tr><td>含义</td><td>实际值相对真实条件均值的偏离</td><td>实际值相对估计条件均值的偏离</td></tr></tbody></table></div><div class="equation">eᵢ = uᵢ − (β̂₀ − β₀) − (β̂₁ − β₁)Xᵢ。</div><p class="">因此,残差与扰动项并非完全相同。含截距 OLS 还满足 ΣXᵢeᵢ = 0;这些是拟合所得的样本代数性质,不能据此证明总体扰动与解释变量无关。若线性条件均值设定不成立,拟合残差还会包含函数形式误设的影响。</p><p class="note"><strong>关于“总体回归曲线”</strong>:总体回归函数是 E(Y | X),本题将它设定为 β₀ + β₁X。工作簿没有说明所列家庭是否覆盖某个明确总体的全部成员,因此本文将拟合直线称为“总体回归函数的估计(样本回归线)”。各收入组的实际平均消费是组内经验均值,也不直接当作已知的真实总体条件均值。</p><h2 id="data">2. 数据整理与原表核对</h2><p class="">工作表采用横向分组布局:C3:L3 为 10 个收入水平(800、1100、…、3500),C4:L16 为家庭消费明细,C17:L17 为原表合计。标题文字在源工作簿中已有乱码,数字单元格可正常读取;变量含义依据给定示例图和表格结构确认。</p><p class="">整理过程:读取 C3:L17;核对收入表头;分别计算每列明细和并与末行合计比较;移除表头及合计行;将消费列转换为长表;删除空白明细;保留收入、消费和原 Excel 行号。空白不视为 0;相同金额的重复记录保留,因为可能对应不同家庭。每条明细等权,共得到 98 条记录。</p><p class="warning"><strong>发现 4 组明细与原表合计不一致。</strong> 差额按“明细之和 − 原表合计”定义。以下Line truncated
-ArgumentList &#x27;/e do &quot;C:\Users\cattom\Documents\econometrics\Week7\week7_analysis.do&quot;&#x27; `
-WorkingDirectory &quot;C:\Users\cattom\Documents\econometrics\Week7&quot; `
-WindowStyle Hidden -Wait</code></pre><p class="">下列为主要估计与绘图指令摘录;前置数据整理和完整图形样式以完整 do 文件为准:</p><pre><code>use &quot;C:/Users/cattom/Documents/econometrics/Week7/households_clean.dta&quot;, clear
regress consume income
predict double fitted, xb
predict double residual, residuals
twoway (scatter consume income) (lfit consume income), ///
title(&quot;不同可支配收入水平组家庭消费支出的条件分布图&quot;) ///
xtitle(&quot;每月可支配收入(元)&quot;) ytitle(&quot;每月消费支出(元)&quot;)
regress consume income, vce(robust)</code></pre><p class="">Stata 运行后,在工作目录执行以下命令可独立核对数值并重建两份报告。此辅助脚本需要 Python、NumPy、SciPy 和 openpyxl;它读取 Stata 输出,不替代 Stata 回归或作图。</p><pre><code>python build_week7_report.py</code></pre><p class=""><strong>已完成验证</strong>:独立从 Excel 明细构建设计矩阵,用 NumPy 复算 OLS,并核对 98 条记录、系数、拟合值、残差、R²、Root MSE、常规及 HC1 标准误和双侧 t 检验 p 值;核对分组汇总和合计差异;检查 Stata 日志成功结束及图形文件结构。验证结果保存于 <code>verification.json</code>。</p><h2 id="files">6. 交付文件索引</h2><div class="table-wrap"><table><thead><tr><th scope="col">文件</th><th scope="col">内容</th></tr></thead><tbody><tr><td><a href="Week7_回归分析报告.md" download>Week7_回归分析报告.md</a></td><td>Markdown 文档,包含研究过程、结果及图片相对引用</td></tr><tr><td><a href="Week7_回归分析报告.html" download>Week7_回归分析报告.html</a></td><td>HTML5 页面,图形与样式内嵌,可离线阅读</td></tr><tr><td><a href="week7_analysis.do" download>week7_analysis.do</a></td><td>完整、可复现的 Stata 分析脚本</td></tr><tr><td><a href="week7_stata.log" download>week7_stata.log</a></td><td>Stata 纯文本分析日志,含回归、分组及检验输出</td></tr><tr><td><a href="consumption_fit.png" download>consumption_fit.png</a></td><td>仿照示例生成的 1800 像素宽图形</td></tr><tr><td><a href="consumption_fit.svg" download>consumption_fit.svg</a></td><td>可缩放矢量图</td></tr><tr><td><a href="consumption_fit.pdf" download>consumption_fit.pdf</a></td><td>适合打印的图形</td></tr><tr><td><a href="consumption_fit.gph" download>consumption_fit.gph</a></td><td>Stata 原生图形,可用 graph use 打开</td></tr><tr><td><a href="households_clean.dta" download>households_clean.dta</a></td><td>98 条清洗后家庭明细;同名 CSV 同时提供</td></tr><tr><td><a href="households_fitted.dta" download>households_fitted.dta</a></td><td>含拟合值、残差、残差平方的明细;同名 CSV 同时提供</td></tr><tr><td><a href="income_group_summary.csv" download>income_group_summary.csv</a></td><td>收入组人数、均值、标准差、范围和拟合均值;另存 DTA</td></tr><tr><td><a href="source_totals_audit.csv" download>source_totals_audit.csv</a></td><td>明细合计与原表合计差异审计;另存 DTA</td></tr><tr><td><a href="regression_coefficients.csv" download>regression_coefficients.csv</a></td><td>常规系数、标准误、t 值、p 值及区间;另存 DTA</td></tr><tr><td><a href="robust_coefficients.csv" download>robust_coefficients.csv</a></td><td>HC1 稳健系数表;另存 DTA</td></tr><tr><td><a href="model_statistics.csv" download>model_statistics.csv</a></td><td>拟合优度、残差核对与异方差检验统计量</td></tr><tr><td><a href="consumption_ols.ster" download>consumption_ols.ster</a></td><td>可由 estimates use 重新载入的 OLS 估计结果</td></tr><tr><td><a href="consumption_robust.ster" download>consumption_robust.ster</a></td><td>稳健标准误版本的估计结果</td></tr><tr><td><a href="build_week7_report.py" download>build_week7_report.py</a></td><td>独立验证与文档生成脚本</td></tr><tr><td><a href="verification.json" download>verification.json</a></td><td>数值验证状态及原始 Excel 的 SHA-256 指纹</td></tr></tbody></table></div><p class="">原始 Excel 与参考 PNG 保留在 Eg2_1_1 文件夹中。Stata 批处理另会自动生成 week7_analysis.log。Markdown 需与图形文件保留相对位置;HTML 页面本身可单独打开阅读,其文件下载链接需相邻产物仍在原目录。</p><h2 id="sources">7. 方法依据与来源</h2><p class="">数值结果以本地原始 Excel、Stata 实际执行日志及独立数值核验为依据;Stata 指令含义核对了本机随软件附带的官方帮助文件。以下编号对应正文的方法引用:</p><div class="table-wrap"><table><thead><tr><th scope="col">编号</th><th scope="col">来源</th><th scope="col">使用内容</th></tr></thead><tbody><tr><td>[1]</td><td>D:/Stata15/ado/base/r/regress.sthlp</td><td>OLS、vce(robust) 与 HC1 的 n/(n−k) 修正</td></tr><tr><td>[2]</td><td>D:/Stata15/ado/base/r/regress_postestimation.sthlp</td><td>线性预测 xb、残差 residuals 与 estat hettest</td></tr><tr><td>[3]</td><td>D:/Stata15/ado/base/t/twoway_lfit.sthlp</td><td>由一元线性回归预测值绘制拟合线</td></tr><tr><td>[4]</td><td>Eg2_1_1/Eg2_1_1.xlsx 与 Eg2_1_1/Eg2_1_1.png</td><td>原始数值、变量含义及仿图样式</td></tr></tbody></table></div><p class="">随机扰动与残差的比较依据正文给出的总体条件均值定义及 OLS 正规方程推导。未将原表合计作为新增观测,也未假定已知真实总体Line truncated
<script>
const slider = document.getElementById('income-slider');
slider.addEventListener('input', () => {
const income = Number(slider.value);
document.getElementById('income-value').textContent = income.toFixed(0);
document.getElementById('pred-value').textContent = (22.9309341033397 + 0.728798741695425 * income).toFixed(2);
});
</script></body></html>
+196
View File
@@ -0,0 +1,196 @@
# Week 7:随机扰动项、残差与家庭消费回归
研究日期:2026 年 10 月 23 日。数据:Eg2_1_1/Eg2_1_1.xlsx(Sheet1)。实际执行软件:Stata/SE 15.1,路径 D:/Stata15/StataSE-64.exe;脚本使用 version 15.0 语法。
本研究使用原表 98 条家庭消费明细,估计每月可支配收入与每月消费支出的线性关系,并参照给定图片完成 Stata 作图。所有金额单位均为元。
> Ŷ = 22.9309 + 0.728799X;n = 98;R² = 0.930666
## 1. 随机扰动项与残差项
**随机扰动项** uᵢ 是实际观测值与真实总体条件均值之间的偏差。写作 Yᵢ = m(Xᵢ) + uᵢ,其中 m(Xᵢ) = E(Yᵢ | Xᵢ)。它反映给定收入后,家庭偏好、人口规模、其他未纳入因素及随机变化造成的消费差异。真实总体条件均值通常未知,因此 uᵢ 通常不可直接观测。
> uᵢ = Yᵢ − E(Yᵢ | Xᵢ);若 m(Xᵢ) = β₀ + β₁Xᵢ,则 uᵢ = Yᵢ − β₀ − β₁Xᵢ。
**残差项** eᵢ 是实际观测值与拟合值之间的偏差。它在估计回归系数后可以计算,是对相应随机扰动的估计。
> eᵢ = Yᵢ − Ŷᵢ = Yᵢ − β̂₀ − β̂₁Xᵢ。
| 比较维度 | 随机扰动项 uᵢ | 残差项 eᵢ |
| --- | --- | --- |
| 参照对象 | 真实总体回归函数 E(Y \| X) | 利用数据估计的回归函数 Ŷ |
| 参数 | 真实且通常未知的 β₀、β₁ | 可由数据算出的 β̂₀、β̂₁ |
| 能否直接计算 | 通常不能 | 拟合后可以 |
| 零均值性质 | 以真实条件均值定义时 E(u \| X) = 0;设定线性模型时需相应条件成立 | 含截距 OLS 的样本残差满足 Σeᵢ = 0(数值计算有舍入误差) |
| 含义 | 实际值相对真实条件均值的偏离 | 实际值相对估计条件均值的偏离 |
> eᵢ = uᵢ − (β̂₀ − β₀) − (β̂₁ − β₁)Xᵢ。
因此,残差与扰动项并非完全相同。含截距 OLS 还满足 ΣXᵢeᵢ = 0;这些是拟合所得的样本代数性质,不能据此证明总体扰动与解释变量无关。若线性条件均值设定不成立,拟合残差还会包含函数形式误设的影响。
**关于“总体回归曲线”**:总体回归函数是 E(Y | X),本题将它设定为 β₀ + β₁X。工作簿没有说明所列家庭是否覆盖某个明确总体的全部成员,因此本文将拟合直线称为“总体回归函数的估计(样本回归线)”。各收入组的实际平均消费是组内经验均值,也不直接当作已知的真实总体条件均值。
## 2. 数据整理与原表核对
工作表采用横向分组布局:C3:L3 为 10 个收入水平(800、1100、…、3500),C4:L16 为家庭消费明细,C17:L17 为原表合计。标题文字在源工作簿中已有乱码,数字单元格可正常读取;变量含义依据给定示例图和表格结构确认。
整理过程:读取 C3:L17;核对收入表头;分别计算每列明细和并与末行合计比较;移除表头及合计行;将消费列转换为长表;删除空白明细;保留收入、消费和原 Excel 行号。空白不视为 0;相同金额的重复记录保留,因为可能对应不同家庭。每条明细等权,共得到 98 条记录。
**发现 4 组明细与原表合计不一致。** 差额按“明细之和 − 原表合计”定义。以下差异不足以判断究竟是明细录入错误、合计错误还是遗漏,因此不补造记录,也不按合计反推消费值;回归仅依据现有明细。
| 收入 X | 记录数 | 明细之和 | 原表合计 | 差额 |
| --- | --- | --- | --- | --- |
| 800 | 4 | 2420 | 2420 | +0 |
| 1100 | 6 | 4950 | 4950 | +0 |
| 1400 | 11 | 11495 | 11495 | +0 |
| 1700 | 13 | 16445 | 16445 | +0 |
| 2000 | 13 | 19305 | 19305 | +0 |
| 2300 | 13 | 21868 | 23870 | -2002 |
| 2600 | 13 | 25025 | 25025 | +0 |
| 2900 | 10 | 21362 | 21450 | -88 |
| 3200 | 9 | 21153 | 21285 | -132 |
| 3500 | 6 | 15499 | 15510 | -11 |
特别是收入 2300 元组,明细之和为 21868 元,而原表合计为 23870 元,差额为 −2002 元。应先向数据提供者核实,再考虑更正;本次结果对应当前文件的可见明细。
## 3. 回归设定、过程与估计结果
设 X 为家庭每月可支配收入,Y 为每月消费支出。假定总体条件均值为线性形式:E(Y | X) = β₀ + β₁X;使用普通最小二乘法(OLS)选择截距和斜率,使 98 条明细的残差平方和最小。[1]
> min Σ(Yᵢ − β̂₀ − β̂₁Xᵢ)²;β̂₁ = Σ(Xᵢ − X̄)(Yᵢ − Ȳ) / Σ(Xᵢ − X̄)²;β̂₀ = Ȳ − β̂₁X̄。
样本平均收入 X̄ = 2202.0408 元,平均消费 Ȳ = 1627.7755 元。Stata 命令为 `regress consume income`,并使用 `predict ..., xb` 与 `predict ..., residuals` 保存拟合值及残差。[1][2]
> Ŷ = 22.930934 + 0.728798742X
| 变量 | 系数 | 常规标准误 | t 值 | p 值 | 常规 95% 置信区间 |
| --- | --- | --- | --- | --- | --- |
| 收入 X | 0.728799 | 0.020302 | 35.8970 | 1.952e-57 | [0.688499, 0.769099] |
| 截距 | 22.930934 | 47.096629 | 0.4869 | 0.627445 | [-70.555136, 116.417004] |
| 指标 | 结果 |
| --- | --- |
| 观测数 / 残差自由度 | 98 / 96 |
| R² / 调整 R² | 0.930666 / 0.929943 |
| Root MSE(元) | 146.627814 |
| 残差平方和(元²) | 2063972.732587 |
| 常规 F(1,96) / p 值 | 1288.595737 / 1.952e-57 |
**经济含义**:在这组数据的线性拟合中,收入每高 1 元,拟合的平均消费约高 0.7288 元;每高 100 元,约高 72.88 元。可将斜率描述为估计的边际消费倾向,但单变量描述性回归不能独自识别收入对消费的因果作用。
R² = 0.9307 表示收入的线性拟合解释了本数据中约 93.07% 的消费总离差平方和。它不是预测准确率,也不能证明不存在遗漏变量。截距对应收入为 0 时的拟合消费,但 0 超出观测收入范围 800—3500 元,因而不作实质经济解释。
**补充稳健性核对**:`estat hettest` 的 Breusch–Pagan / Cook–Weisberg 检验为 χ²(1) = 8.7005,p = 0.003181,在其检验条件下拒绝同方差原假设。另运行 `regress consume income, vce(robust)` 计算 HC1 稳健标准误;回归系数和拟合直线保持一致。[1][2]
| 变量 | HC1 稳健标准误 | 稳健 t 值 | 稳健 p 值 | 稳健 95% 置信区间 |
| --- | --- | --- | --- | --- |
| 收入 X | 0.021428 | 34.0122 | 2.381e-55 | [0.686265, 0.771332] |
| 截距 | 43.447563 | 0.5278 | 0.598867 | [-63.311797, 109.173665] |
采用稳健标准误后,收入系数仍显著为正。稳健推断仍依赖相应抽样、独立性及大样本近似条件;数据没有提供抽样设计信息,且存在上述合计差异,所以结果宜作本组数据的教学性、描述性分析。
## 4. 仿照示例图作图与残差解释
Stata 使用 `twoway (scatter consume income) (lfit consume income)` 作图:深蓝色圆点表示家庭消费明细,红线表示 OLS 拟合的条件均值。横轴为每月可支配收入,纵轴为每月消费支出;淡蓝背景、白色绘图区、中文标题及底部图例均参照给定图片。[3]
![图 1|Stata 生成的家庭消费散点与线性拟合图](consumption_fit.png)
每个固定收入水平上的竖直点列展示该收入组的经验消费分布。若收入、消费均相同,点会重合,所以图上可分辨的点数可能小于 98;这些观测在回归中全部保留。红线估计条件均值,不能代表每户家庭的实际消费。
按收入组得到的明细均值与拟合均值如下。回归直接使用 98 条家庭明细,未对 10 个组均值作不加权回归;各组家庭数量不同,不能随意替换分析单位。
| 收入 X | 家庭数 | 组内平均消费 | 拟合均值 Ŷ | 平均残差 |
| --- | --- | --- | --- | --- |
| 800 | 4 | 605.000 | 605.970 | -0.970 |
| 1100 | 6 | 825.000 | 824.610 | +0.390 |
| 1400 | 11 | 1045.000 | 1043.249 | +1.751 |
| 1700 | 13 | 1265.000 | 1261.889 | +3.111 |
| 2000 | 13 | 1485.000 | 1480.528 | +4.472 |
| 2300 | 13 | 1682.154 | 1699.168 | -17.014 |
| 2600 | 13 | 1925.000 | 1917.808 | +7.192 |
| 2900 | 10 | 2136.200 | 2136.447 | -0.247 |
| 3200 | 9 | 2350.333 | 2355.087 | -4.754 |
| 3500 | 6 | 2583.167 | 2573.727 | +9.440 |
**残差例子**:Excel 单元格 C4 对应收入 800 元、消费 561 元。其拟合消费为 605.9699 元,所以 e = 561 − 605.9699 = -44.9699 元。负号表示这户家庭的实际消费低于拟合条件均值;这不是已知的真实随机扰动 u。
数值核对:Σeᵢ = -1.955e-11,ΣXᵢeᵢ = -7.333e-08。两者在浮点精度下接近 0,与含截距 OLS 的正规方程一致;Root MSE = √[Σeᵢ²/(98−2)] = 146.6278 元。
[原始参考图](Eg2_1_1/Eg2_1_1.png)
## 5. 复现方法与 Stata 指令
完整脚本 `week7_analysis.do` 从原始 Excel 开始,依次完成合计审计、长表转换、OLS 回归、拟合值与残差生成、图形导出、稳健标准误及异方差检验。脚本无需安装 Stata 扩展包。在 Stata 命令窗口运行:
```stata
do "C:/Users/cattom/Documents/econometrics/Week7/week7_analysis.do"
```
也可以在 Windows PowerShell 中后台执行。以下命令会等待 Stata 完成;重跑会更新同名分析产物:
```powershell
Start-Process -FilePath "D:\Stata15\StataSE-64.exe" `
-ArgumentList '/e do "C:\Users\cattom\Documents\econometrics\Week7\week7_analysis.do"' `
-WorkingDirectory "C:\Users\cattom\Documents\econometrics\Week7" `
-WindowStyle Hidden -Wait
```
下列为主要估计与绘图指令摘录;前置数据整理和完整图形样式以完整 do 文件为准:
```stata
use "C:/Users/cattom/Documents/econometrics/Week7/households_clean.dta", clear
regress consume income
predict double fitted, xb
predict double residual, residuals
twoway (scatter consume income) (lfit consume income), ///
title("不同可支配收入水平组家庭消费支出的条件分布图") ///
xtitle("每月可支配收入(元)") ytitle("每月消费支出(元)")
regress consume income, vce(robust)
```
Stata 运行后,在工作目录执行以下命令可独立核对数值并重建两份报告。此辅助脚本需要 Python、NumPy、SciPy 和 openpyxl;它读取 Stata 输出,不替代 Stata 回归或作图。
```powershell
python build_week7_report.py
```
**已完成验证**:独立从 Excel 明细构建设计矩阵,用 NumPy 复算 OLS,并核对 98 条记录、系数、拟合值、残差、R²、Root MSE、常规及 HC1 标准误和双侧 t 检验 p 值;核对分组汇总和合计差异;检查 Stata 日志成功结束及图形文件结构。验证结果保存于 `verification.json`。
## 6. 交付文件索引
| 文件 | 内容 |
| --- | --- |
| [Week7_回归分析报告.md](Week7_回归分析报告.md) | Markdown 文档,包含研究过程、结果及图片相对引用 |
| [Week7_回归分析报告.html](Week7_回归分析报告.html) | HTML5 页面,图形与样式内嵌,可离线阅读 |
| [week7_analysis.do](week7_analysis.do) | 完整、可复现的 Stata 分析脚本 |
| [week7_stata.log](week7_stata.log) | Stata 纯文本分析日志,含回归、分组及检验输出 |
| [consumption_fit.png](consumption_fit.png) | 仿照示例生成的 1800 像素宽图形 |
| [consumption_fit.svg](consumption_fit.svg) | 可缩放矢量图 |
| [consumption_fit.pdf](consumption_fit.pdf) | 适合打印的图形 |
| [consumption_fit.gph](consumption_fit.gph) | Stata 原生图形,可用 graph use 打开 |
| [households_clean.dta](households_clean.dta) | 98 条清洗后家庭明细;同名 CSV 同时提供 |
| [households_fitted.dta](households_fitted.dta) | 含拟合值、残差、残差平方的明细;同名 CSV 同时提供 |
| [income_group_summary.csv](income_group_summary.csv) | 收入组人数、均值、标准差、范围和拟合均值;另存 DTA |
| [source_totals_audit.csv](source_totals_audit.csv) | 明细合计与原表合计差异审计;另存 DTA |
| [regression_coefficients.csv](regression_coefficients.csv) | 常规系数、标准误、t 值、p 值及区间;另存 DTA |
| [robust_coefficients.csv](robust_coefficients.csv) | HC1 稳健系数表;另存 DTA |
| [model_statistics.csv](model_statistics.csv) | 拟合优度、残差核对与异方差检验统计量 |
| [consumption_ols.ster](consumption_ols.ster) | 可由 estimates use 重新载入的 OLS 估计结果 |
| [consumption_robust.ster](consumption_robust.ster) | 稳健标准误版本的估计结果 |
| [build_week7_report.py](build_week7_report.py) | 独立验证与文档生成脚本 |
| [verification.json](verification.json) | 数值验证状态及原始 Excel 的 SHA-256 指纹 |
原始 Excel 与参考 PNG 保留在 Eg2_1_1 文件夹中。Stata 批处理另会自动生成 week7_analysis.log。Markdown 需与图形文件保留相对位置;HTML 页面本身可单独打开阅读,其文件下载链接需相邻产物仍在原目录。
## 7. 方法依据与来源
数值结果以本地原始 Excel、Stata 实际执行日志及独立数值核验为依据;Stata 指令含义核对了本机随软件附带的官方帮助文件。以下编号对应正文的方法引用:
| 编号 | 来源 | 使用内容 |
| --- | --- | --- |
| [1] | D:/Stata15/ado/base/r/regress.sthlp | OLS、vce(robust) 与 HC1 的 n/(n−k) 修正 |
| [2] | D:/Stata15/ado/base/r/regress_postestimation.sthlp | 线性预测 xb、残差 residuals 与 estat hettest |
| [3] | D:/Stata15/ado/base/t/twoway_lfit.sthlp | 由一元线性回归预测值绘制拟合线 |
| [4] | Eg2_1_1/Eg2_1_1.xlsx 与 Eg2_1_1/Eg2_1_1.png | 原始数值、变量含义及仿图样式 |
随机扰动与残差的比较依据正文给出的总体条件均值定义及 OLS 正规方程推导。未将原表合计作为新增观测,也未假定已知真实总体参数。
+275
View File
@@ -0,0 +1,275 @@
"""Verify Stata outputs against Excel and regenerate the two offline reports.
Requires: numpy, scipy, openpyxl. Run after week7_analysis.do.
"""
from pathlib import Path
import base64
import csv
import hashlib
import html
import json
import re
import xml.etree.ElementTree as ET
import numpy as np
from scipy import stats
from openpyxl import load_workbook
ROOT = Path(__file__).resolve().parent
def read_csv(name):
with (ROOT / name).open(encoding='utf-8-sig', newline='') as f:
return list(csv.DictReader(f))
def numeric(row):
return {k: float(v) for k, v in row.items()}
model = numeric(read_csv('model_statistics.csv')[0])
coeff = {r['term']: {k: float(v) for k, v in r.items() if k != 'term'} for r in read_csv('regression_coefficients.csv')}
robust = {r['term']: {k: float(v) for k, v in r.items() if k != 'term'} for r in read_csv('robust_coefficients.csv')}
groups = [numeric(r) for r in read_csv('income_group_summary.csv')]
audit = [numeric(r) for r in read_csv('source_totals_audit.csv')]
fitted = [numeric(r) for r in read_csv('households_fitted.csv')]
# Independent numerical validation: derive everything directly from source cells.
workbook = load_workbook(ROOT / 'Eg2_1_1/Eg2_1_1.xlsx', data_only=True)
sheet = workbook['Sheet1']
source = []
for col in range(3, 13):
for row in range(4, 17):
value = sheet.cell(row, col).value
if value is not None:
source.append((row, float(sheet.cell(3, col).value), float(value)))
source_array = np.array(source)
assert len(source) == 98
assert all((r['excel_row'], r['income'], r['consume']) == item for r, item in zip(fitted, source))
x, y = source_array[:, 1], source_array[:, 2]
X = np.column_stack([np.ones(len(x)), x])
beta = np.linalg.lstsq(X, y, rcond=None)[0]
yhat = X @ beta
resid = y - yhat
n, k = X.shape
inv = np.linalg.inv(X.T @ X)
rss = resid @ resid
se = np.sqrt(np.diag((rss / (n-k)) * inv))
hc1 = inv @ (X.T @ (X * (resid ** 2)[:, None])) @ inv * n / (n-k)
se_hc1 = np.sqrt(np.diag(hc1))
np.testing.assert_allclose([model['intercept'], model['slope']], beta, rtol=1e-10, atol=1e-9)
np.testing.assert_allclose([r['fitted'] for r in fitted], yhat, rtol=1e-10, atol=1e-8)
np.testing.assert_allclose([r['residual'] for r in fitted], resid, rtol=1e-10, atol=1e-8)
for i, term in enumerate(['_cons', 'income']):
np.testing.assert_allclose(coeff[term]['se'], se[i], rtol=1e-10)
np.testing.assert_allclose(robust[term]['se'], se_hc1[i], rtol=1e-10)
for output, standard_error in [(coeff[term], se[i]), (robust[term], se_hc1[i])]:
p = 2 * stats.t.sf(abs(beta[i] / standard_error), n-k)
np.testing.assert_allclose(output['p'], p, rtol=1e-9, atol=0)
np.testing.assert_allclose(model['r_squared'], 1-rss/np.sum((y-y.mean())**2), rtol=1e-12)
np.testing.assert_allclose(model['root_mse'], np.sqrt(rss/(n-k)), rtol=1e-12)
for g, a in zip(groups, audit):
yy = y[x == g['income']]
assert g['n'] == len(yy) == a['n']
assert a['detail_total'] == yy.sum()
np.testing.assert_allclose(g['mean_consume'], yy.mean(), rtol=1e-12)
assert a['difference'] == a['detail_total'] - a['reported_total']
log = (ROOT / 'week7_stata.log').read_text(encoding='utf-8', errors='replace')
assert 'WEEK7_ANALYSIS_COMPLETED' in log
assert not re.search(r'^r\(\d+\);', log, flags=re.M)
assert (ROOT / 'consumption_fit.png').read_bytes().startswith(b'\x89PNG')
assert (ROOT / 'consumption_fit.pdf').read_bytes().startswith(b'%PDF')
ET.parse(ROOT / 'consumption_fit.svg')
assert '不同可支配收入水平' in (ROOT / 'week7_analysis.do').read_text(encoding='utf-8')
verification = {
'status': 'passed', 'date': '2026-10-23', 'observations': n,
'source_sha256': hashlib.sha256((ROOT/'Eg2_1_1/Eg2_1_1.xlsx').read_bytes()).hexdigest(),
'independent_ols_intercept': float(beta[0]), 'independent_ols_slope': float(beta[1]),
'max_abs_fitted_difference': float(np.max(np.abs(np.array([r['fitted'] for r in fitted])-yhat))),
'checks': ['all 98 Excel source records match Stata data, including worksheet row',
'OLS coefficients, fitted values, residuals, R-squared, RMSE',
'conventional and HC1 standard errors and two-sided t-test p-values',
'all income-group counts, means, and source-total differences',
'Stata log completion and no r() errors', 'PNG, SVG, and PDF file structure']
}
(ROOT / 'verification.json').write_text(json.dumps(verification, ensure_ascii=False, indent=2), encoding='utf-8')
md, body = [], []
sections = []
def inline(text):
text = html.escape(text)
text = re.sub(r'`([^`]+)`', r'<code>\1</code>', text)
text = re.sub(r'\*\*([^*]+)\*\*', r'<strong>\1</strong>', text)
return text
def heading(title, anchor):
md.append('## ' + title)
body.append(f'<h2 id="{anchor}">{html.escape(title)}</h2>')
sections.append((title, anchor))
def paragraph(text, cls=''):
md.append(text)
body.append(f'<p class="{cls}">{inline(text)}</p>')
def equation(text):
md.append('> ' + text)
body.append(f'<div class="equation">{html.escape(text)}</div>')
def table(headers, rows):
md.append('| ' + ' | '.join(headers) + ' |\n| ' + ' | '.join(['---']*len(headers)) + ' |\n' + '\n'.join('| ' + ' | '.join(str(c).replace('|', r'\|') for c in r) + ' |' for r in rows))
body.append('<div class="table-wrap"><table><thead><tr>' + ''.join('<th scope="col">'+inline(h)+'</th>' for h in headers) + '</tr></thead><tbody>' + ''.join('<tr>'+''.join('<td>'+inline(str(c))+'</td>' for c in row)+'</tr>' for row in rows) + '</tbody></table></div>')
def code(text, lang='stata'):
md.append('```'+lang+'\n'+text+'\n```')
body.append('<pre><code>'+html.escape(text)+'</code></pre>')
def image(path, alt):
md.append(f'![{alt}]({path})')
encoded = base64.b64encode((ROOT/path).read_bytes()).decode()
body.append(f'<figure><img src="data:image/png;base64,{encoded}" alt="{html.escape(alt)}"><figcaption>{html.escape(alt)}</figcaption></figure>')
def asset_link(path, label):
return f'<a href="{html.escape(path, quote=True)}" download>{html.escape(label)}</a>'
md.append('# Week 7:随机扰动项、残差与家庭消费回归')
paragraph('研究日期:2026 年 10 月 23 日。数据:Eg2_1_1/Eg2_1_1.xlsx(Sheet1)。实际执行软件:Stata/SE 15.1,路径 D:/Stata15/StataSE-64.exe;脚本使用 version 15.0 语法。')
paragraph('本研究使用原表 98 条家庭消费明细,估计每月可支配收入与每月消费支出的线性关系,并参照给定图片完成 Stata 作图。所有金额单位均为元。')
equation(f'Ŷ = {model["intercept"]:.4f} + {model["slope"]:.6f}X;n = 98;R² = {model["r_squared"]:.6f}')
heading('1. 随机扰动项与残差项', 'concepts')
paragraph('**随机扰动项** uᵢ 是实际观测值与真实总体条件均值之间的偏差。写作 Yᵢ = m(Xᵢ) + uᵢ,其中 m(Xᵢ) = E(Yᵢ | Xᵢ)。它反映给定收入后,家庭偏好、人口规模、其他未纳入因素及随机变化造成的消费差异。真实总体条件均值通常未知,因此 uᵢ 通常不可直接观测。')
equation('uᵢ = Yᵢ − E(Yᵢ | Xᵢ);若 m(Xᵢ) = β₀ + β₁Xᵢ,则 uᵢ = Yᵢ − β₀ − β₁Xᵢ。')
paragraph('**残差项** eᵢ 是实际观测值与拟合值之间的偏差。它在估计回归系数后可以计算,是对相应随机扰动的估计。')
equation('eᵢ = Yᵢ − Ŷᵢ = Yᵢ − β̂₀ − β̂₁Xᵢ。')
table(['比较维度', '随机扰动项 uᵢ', '残差项 eᵢ'], [
['参照对象', '真实总体回归函数 E(Y | X)', '利用数据估计的回归函数 Ŷ'],
['参数', '真实且通常未知的 β₀、β₁', '可由数据算出的 β̂₀、β̂₁'],
['能否直接计算', '通常不能', '拟合后可以'],
['零均值性质', '以真实条件均值定义时 E(u | X) = 0;设定线性模型时需相应条件成立', '含截距 OLS 的样本残差满足 Σeᵢ = 0(数值计算有舍入误差)'],
['含义', '实际值相对真实条件均值的偏离', '实际值相对估计条件均值的偏离']
])
equation('eᵢ = uᵢ − (β̂₀ − β₀) − (β̂₁ − β₁)Xᵢ。')
paragraph('因此,残差与扰动项并非完全相同。含截距 OLS 还满足 ΣXᵢeᵢ = 0;这些是拟合所得的样本代数性质,不能据此证明总体扰动与解释变量无关。若线性条件均值设定不成立,拟合残差还会包含函数形式误设的影响。')
paragraph('**关于“总体回归曲线”**:总体回归函数是 E(Y | X),本题将它设定为 β₀ + β₁X。工作簿没有说明所列家庭是否覆盖某个明确总体的全部成员,因此本文将拟合直线称为“总体回归函数的估计(样本回归线)”。各收入组的实际平均消费是组内经验均值,也不直接当作已知的真实总体条件均值。', 'note')
heading('2. 数据整理与原表核对', 'data')
paragraph('工作表采用横向分组布局:C3:L3 为 10 个收入水平(800、1100、…、3500),C4:L16 为家庭消费明细,C17:L17 为原表合计。标题文字在源工作簿中已有乱码,数字单元格可正常读取;变量含义依据给定示例图和表格结构确认。')
paragraph('整理过程:读取 C3:L17;核对收入表头;分别计算每列明细和并与末行合计比较;移除表头及合计行;将消费列转换为长表;删除空白明细;保留收入、消费和原 Excel 行号。空白不视为 0;相同金额的重复记录保留,因为可能对应不同家庭。每条明细等权,共得到 98 条记录。')
paragraph('**发现 4 组明细与原表合计不一致。** 差额按“明细之和 − 原表合计”定义。以下差异不足以判断究竟是明细录入错误、合计错误还是遗漏,因此不补造记录,也不按合计反推消费值;回归仅依据现有明细。', 'warning')
table(['收入 X', '记录数', '明细之和', '原表合计', '差额'], [[f'{a["income"]:.0f}', f'{a["n"]:.0f}', f'{a["detail_total"]:.0f}', f'{a["reported_total"]:.0f}', f'{a["difference"]:+.0f}'] for a in audit])
paragraph('特别是收入 2300 元组,明细之和为 21868 元,而原表合计为 23870 元,差额为 −2002 元。应先向数据提供者核实,再考虑更正;本次结果对应当前文件的可见明细。')
heading('3. 回归设定、过程与估计结果', 'results')
paragraph('设 X 为家庭每月可支配收入,Y 为每月消费支出。假定总体条件均值为线性形式:E(Y | X) = β₀ + β₁X;使用普通最小二乘法(OLS)选择截距和斜率,使 98 条明细的残差平方和最小。[1]')
equation('min Σ(Yᵢ − β̂₀ − β̂₁Xᵢ)²;β̂₁ = Σ(Xᵢ − X̄)(Yᵢ − Ȳ) / Σ(Xᵢ − X̄)²;β̂₀ = Ȳ − β̂₁X̄。')
paragraph(f'样本平均收入 X̄ = {x.mean():.4f} 元,平均消费 Ȳ = {y.mean():.4f} 元。Stata 命令为 `regress consume income`,并使用 `predict ..., xb` 与 `predict ..., residuals` 保存拟合值及残差。[1][2]')
equation(f'Ŷ = {model["intercept"]:.6f} + {model["slope"]:.9f}X')
table(['变量', '系数', '常规标准误', 't 值', 'p 值', '常规 95% 置信区间'], [
['收入 X', f'{coeff["income"]["estimate"]:.6f}', f'{coeff["income"]["se"]:.6f}', f'{coeff["income"]["t"]:.4f}', f'{coeff["income"]["p"]:.3e}', f'[{coeff["income"]["ci_low"]:.6f}, {coeff["income"]["ci_high"]:.6f}]'],
['截距', f'{coeff["_cons"]["estimate"]:.6f}', f'{coeff["_cons"]["se"]:.6f}', f'{coeff["_cons"]["t"]:.4f}', f'{coeff["_cons"]["p"]:.6f}', f'[{coeff["_cons"]["ci_low"]:.6f}, {coeff["_cons"]["ci_high"]:.6f}]']
])
table(['指标', '结果'], [
['观测数 / 残差自由度', '98 / 96'],
['R² / 调整 R²', f'{model["r_squared"]:.6f} / {1-(1-model["r_squared"])*(n-1)/(n-k):.6f}'],
['Root MSE(元)', f'{model["root_mse"]:.6f}'],
['残差平方和(元²)', f'{model["rss"]:.6f}'],
['常规 F(1,96) / p 值', f'{model["F"]:.6f} / {model["p_F"]:.3e}']
])
paragraph('**经济含义**:在这组数据的线性拟合中,收入每高 1 元,拟合的平均消费约高 0.7288 元;每高 100 元,约高 72.88 元。可将斜率描述为估计的边际消费倾向,但单变量描述性回归不能独自识别收入对消费的因果作用。')
paragraph('R² = 0.9307 表示收入的线性拟合解释了本数据中约 93.07% 的消费总离差平方和。它不是预测准确率,也不能证明不存在遗漏变量。截距对应收入为 0 时的拟合消费,但 0 超出观测收入范围 800—3500 元,因而不作实质经济解释。')
paragraph(f'**补充稳健性核对**:`estat hettest` 的 Breusch–Pagan / Cook–Weisberg 检验为 χ²(1) = {model["bp_chi2"]:.4f},p = {model["bp_p"]:.6f},在其检验条件下拒绝同方差原假设。另运行 `regress consume income, vce(robust)` 计算 HC1 稳健标准误;回归系数和拟合直线保持一致。[1][2]')
table(['变量', 'HC1 稳健标准误', '稳健 t 值', '稳健 p 值', '稳健 95% 置信区间'], [
['收入 X', f'{robust["income"]["se"]:.6f}', f'{robust["income"]["t"]:.4f}', f'{robust["income"]["p"]:.3e}', f'[{robust["income"]["ci_low"]:.6f}, {robust["income"]["ci_high"]:.6f}]'],
['截距', f'{robust["_cons"]["se"]:.6f}', f'{robust["_cons"]["t"]:.4f}', f'{robust["_cons"]["p"]:.6f}', f'[{robust["_cons"]["ci_low"]:.6f}, {robust["_cons"]["ci_high"]:.6f}]']
])
paragraph('采用稳健标准误后,收入系数仍显著为正。稳健推断仍依赖相应抽样、独立性及大样本近似条件;数据没有提供抽样设计信息,且存在上述合计差异,所以结果宜作本组数据的教学性、描述性分析。')
heading('4. 仿照示例图作图与残差解释', 'figure')
paragraph('Stata 使用 `twoway (scatter consume income) (lfit consume income)` 作图:深蓝色圆点表示家庭消费明细,红线表示 OLS 拟合的条件均值。横轴为每月可支配收入,纵轴为每月消费支出;淡蓝背景、白色绘图区、中文标题及底部图例均参照给定图片。[3]')
image('consumption_fit.png', '图 1|Stata 生成的家庭消费散点与线性拟合图')
paragraph('每个固定收入水平上的竖直点列展示该收入组的经验消费分布。若收入、消费均相同,点会重合,所以图上可分辨的点数可能小于 98;这些观测在回归中全部保留。红线估计条件均值,不能代表每户家庭的实际消费。')
paragraph('按收入组得到的明细均值与拟合均值如下。回归直接使用 98 条家庭明细,未对 10 个组均值作不加权回归;各组家庭数量不同,不能随意替换分析单位。')
table(['收入 X', '家庭数', '组内平均消费', '拟合均值 Ŷ', '平均残差'], [[f'{g["income"]:.0f}', f'{g["n"]:.0f}', f'{g["mean_consume"]:.3f}', f'{g["fitted_mean"]:.3f}', f'{g["mean_residual"]:+.3f}'] for g in groups])
paragraph(f'**残差例子**:Excel 单元格 C4 对应收入 800 元、消费 561 元。其拟合消费为 {yhat[0]:.4f} 元,所以 e = 561 − {yhat[0]:.4f} = {resid[0]:.4f} 元。负号表示这户家庭的实际消费低于拟合条件均值;这不是已知的真实随机扰动 u。')
paragraph(f'数值核对:Σeᵢ = {model["residual_sum"]:.3e},ΣXᵢeᵢ = {model["income_residual_sum"]:.3e}。两者在浮点精度下接近 0,与含截距 OLS 的正规方程一致;Root MSE = √[Σeᵢ²/(98−2)] = {model["root_mse"]:.4f} 元。')
body.append(f'''<div class="prediction"><label for="income-slider">在观测范围内查看拟合均值</label><div class="prediction-values"><span>每月收入 <output id="income-value">2000</output> 元</span><strong>拟合平均消费 <output id="pred-value">{model['intercept']+model['slope']*2000:.2f}</output> 元</strong></div><input id="income-slider" type="range" min="800" max="3500" step="10" value="2000"><p>中间收入值是线性插值;结果表示拟合条件均值,并非对某户实际消费的保证。</p></div>''')
body.append('<details><summary>查看题目提供的原始参考图</summary>')
# The original image remains available in Markdown as a regular reference link.
md.append('[原始参考图](Eg2_1_1/Eg2_1_1.png)')
original_img = base64.b64encode((ROOT/'Eg2_1_1/Eg2_1_1.png').read_bytes()).decode()
body.append(f'<img src="data:image/png;base64,{original_img}" alt="题目提供的原始参考图"></details>')
heading('5. 复现方法与 Stata 指令', 'reproduce')
paragraph('完整脚本 `week7_analysis.do` 从原始 Excel 开始,依次完成合计审计、长表转换、OLS 回归、拟合值与残差生成、图形导出、稳健标准误及异方差检验。脚本无需安装 Stata 扩展包。在 Stata 命令窗口运行:')
code('do "C:/Users/cattom/Documents/econometrics/Week7/week7_analysis.do"')
paragraph('也可以在 Windows PowerShell 中后台执行。以下命令会等待 Stata 完成;重跑会更新同名分析产物:')
code('Start-Process -FilePath "D:\\Stata15\\StataSE-64.exe" `\n -ArgumentList \'/e do "C:\\Users\\cattom\\Documents\\econometrics\\Week7\\week7_analysis.do"\' `\n -WorkingDirectory "C:\\Users\\cattom\\Documents\\econometrics\\Week7" `\n -WindowStyle Hidden -Wait', 'powershell')
paragraph('下列为主要估计与绘图指令摘录;前置数据整理和完整图形样式以完整 do 文件为准:')
code('use "C:/Users/cattom/Documents/econometrics/Week7/households_clean.dta", clear\nregress consume income\npredict double fitted, xb\npredict double residual, residuals\ntwoway (scatter consume income) (lfit consume income), ///\n title("不同可支配收入水平组家庭消费支出的条件分布图") ///\n xtitle("每月可支配收入(元)") ytitle("每月消费支出(元)")\nregress consume income, vce(robust)')
paragraph('Stata 运行后,在工作目录执行以下命令可独立核对数值并重建两份报告。此辅助脚本需要 Python、NumPy、SciPy 和 openpyxl;它读取 Stata 输出,不替代 Stata 回归或作图。')
code('python build_week7_report.py', 'powershell')
paragraph('**已完成验证**:独立从 Excel 明细构建设计矩阵,用 NumPy 复算 OLS,并核对 98 条记录、系数、拟合值、残差、R²、Root MSE、常规及 HC1 标准误和双侧 t 检验 p 值;核对分组汇总和合计差异;检查 Stata 日志成功结束及图形文件结构。验证结果保存于 `verification.json`。')
heading('6. 交付文件索引', 'files')
assets = [
('Week7_回归分析报告.md', 'Markdown 文档,包含研究过程、结果及图片相对引用'),
('Week7_回归分析报告.html', 'HTML5 页面,图形与样式内嵌,可离线阅读'),
('week7_analysis.do', '完整、可复现的 Stata 分析脚本'),
('week7_stata.log', 'Stata 纯文本分析日志,含回归、分组及检验输出'),
('consumption_fit.png', '仿照示例生成的 1800 像素宽图形'),
('consumption_fit.svg', '可缩放矢量图'),
('consumption_fit.pdf', '适合打印的图形'),
('consumption_fit.gph', 'Stata 原生图形,可用 graph use 打开'),
('households_clean.dta', '98 条清洗后家庭明细;同名 CSV 同时提供'),
('households_fitted.dta', '含拟合值、残差、残差平方的明细;同名 CSV 同时提供'),
('income_group_summary.csv', '收入组人数、均值、标准差、范围和拟合均值;另存 DTA'),
('source_totals_audit.csv', '明细合计与原表合计差异审计;另存 DTA'),
('regression_coefficients.csv', '常规系数、标准误、t 值、p 值及区间;另存 DTA'),
('robust_coefficients.csv', 'HC1 稳健系数表;另存 DTA'),
('model_statistics.csv', '拟合优度、残差核对与异方差检验统计量'),
('consumption_ols.ster', '可由 estimates use 重新载入的 OLS 估计结果'),
('consumption_robust.ster', '稳健标准误版本的估计结果'),
('build_week7_report.py', '独立验证与文档生成脚本'),
('verification.json', '数值验证状态及原始 Excel 的 SHA-256 指纹')
]
md.append('| 文件 | 内容 |\n| --- | --- |\n' + '\n'.join(f'| [{name}]({name}) | {desc} |' for name, desc in assets))
body.append('<div class="table-wrap"><table><thead><tr><th scope="col">文件</th><th scope="col">内容</th></tr></thead><tbody>'+''.join('<tr><td>'+asset_link(name,name)+'</td><td>'+html.escape(desc)+'</td></tr>' for name,desc in assets)+'</tbody></table></div>')
paragraph('原始 Excel 与参考 PNG 保留在 Eg2_1_1 文件夹中。Stata 批处理另会自动生成 week7_analysis.log。Markdown 需与图形文件保留相对位置;HTML 页面本身可单独打开阅读,其文件下载链接需相邻产物仍在原目录。')
heading('7. 方法依据与来源', 'sources')
paragraph('数值结果以本地原始 Excel、Stata 实际执行日志及独立数值核验为依据;Stata 指令含义核对了本机随软件附带的官方帮助文件。以下编号对应正文的方法引用:')
table(['编号', '来源', '使用内容'], [
['[1]', 'D:/Stata15/ado/base/r/regress.sthlp', 'OLS、vce(robust) 与 HC1 的 n/(n−k) 修正'],
['[2]', 'D:/Stata15/ado/base/r/regress_postestimation.sthlp', '线性预测 xb、残差 residuals 与 estat hettest'],
['[3]', 'D:/Stata15/ado/base/t/twoway_lfit.sthlp', '由一元线性回归预测值绘制拟合线'],
['[4]', 'Eg2_1_1/Eg2_1_1.xlsx 与 Eg2_1_1/Eg2_1_1.png', '原始数值、变量含义及仿图样式']
])
paragraph('随机扰动与残差的比较依据正文给出的总体条件均值定义及 OLS 正规方程推导。未将原表合计作为新增观测,也未假定已知真实总体参数。')
(ROOT/'Week7_回归分析报告.md').write_text('\n\n'.join(md)+'\n', encoding='utf-8')
style = '''
:root{color-scheme:light;--ink:#182c40;--muted:#5c6d7b;--accent:#146b72;--line:#dce5e9;--paper:#fff;--bg:#f3f6f7}*{box-sizing:border-box}html{scroll-behavior:smooth;scroll-padding-top:24px}body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.85 "Microsoft YaHei","PingFang SC",system-ui,sans-serif}a{color:var(--accent);text-underline-offset:3px}header{background:#143044;color:white;padding:56px 32px 44px}.hero{max-width:1080px;margin:auto}.eyebrow{letter-spacing:3px;color:#a6d7d9;font-size:12px;font-weight:700}h1{font-size:clamp(28px,4.4vw,46px);line-height:1.4;margin:14px 0 16px;letter-spacing:-1px}.subhead{color:#c7d7e0;max-width:760px;margin:0}.metrics{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-top:30px}.metric{border-top:1px solid #547080;padding:14px 0 0}.metric span{display:block;font-size:12px;color:#bacfd9}.metric strong{font-size:27px;font-weight:600;font-variant-numeric:tabular-nums}.layout{max-width:1240px;margin:auto;display:grid;grid-template-columns:200px minmax(0,1fr);gap:38px;padding:34px 28px 70px}nav{position:sticky;top:24px;align-self:start;font-size:13px}nav .nav-title{color:var(--muted);margin:0 0 12px;font-size:11px;letter-spacing:2px}nav a{display:block;text-decoration:none;color:var(--muted);padding:8px 12px;border-left:2px solid var(--line)}nav a:hover,nav a:focus{border-color:var(--accent);color:var(--accent);background:#e7eff0}main{min-width:0;background:var(--paper);padding:30px 36px 42px;border:1px solid var(--line);border-radius:8px}h2{font-size:23px;line-height:1.5;margin:42px 0 18px;padding-top:24px;border-top:1px solid var(--line);scroll-margin-top:24px}p{margin:15px 0}strong{font-weight:650}.equation{font-family:"Cambria Math","Microsoft YaHei",serif;font-size:19px;line-height:1.8;background:#edf5f5;color:#154d58;border-left:3px solid #329097;padding:17px 22px;margin:22px 0;overflow-wrap:anywhere}.note,.warning{padding:17px 20px;background:#f0f5f8;border-radius:4px}.warning{background:#fff6e7;border-left:3px solid #c18a29}.table-wrap{overflow-x:auto;margin:20px 0;border:1px solid var(--line);border-radius:5px}table{width:100%;border-collapse:collapse;font-size:13px;font-variant-numeric:tabular-nums}th{text-align:left;background:#edf2f5;color:#304b5e;font-weight:600;white-space:nowrap}td,th{padding:11px 13px;border-bottom:1px solid var(--line);vertical-align:top}tbody tr:last-child td{border-bottom:0}tbody tr:nth-child(even){background:#fafcfc}td:first-child{white-space:nowrap}code{font:0.88em/1.6 Consolas,"Microsoft YaHei",monospace;background:#edf2f5;padding:2px 5px;border-radius:3px;overflow-wrap:anywhere}pre{background:#182d3d;color:#e5eff5;padding:20px;overflow-x:auto;border-radius:6px;font-size:13px;line-height:1.8}pre code{background:none;color:inherit;padding:0;white-space:pre}figure{margin:24px 0}img{display:block;width:100%;height:auto;border-radius:4px}figcaption{color:var(--muted);text-align:center;font-size:12px;margin-top:9px}details{padding:15px 18px;border:1px solid var(--line);border-radius:5px;margin:20px 0}summary{cursor:pointer;color:var(--accent);font-size:14px}details img{margin-top:20px}.prediction{background:#eff7f6;padding:20px 24px;border:1px solid #cbe3df;border-radius:6px;margin:24px 0}.prediction label{font-weight:600}.prediction-values{display:flex;justify-content:space-between;gap:16px;flex-wrap:wrap;margin-top:12px;font-size:14px}.prediction output{font-variant-numeric:tabular-nums}.prediction input{width:100%;margin:18px 0 0;accent-color:var(--accent)}.prediction p{font-size:12px;color:var(--muted);margin:6px 0 0}footer{text-align:center;padding:0 24px 36px;font-size:12px;color:var(--muted)}@media(max-width:980px){.layout{grid-template-columns:1fr;gap:18px;padding:22px 18px}nav{position:static;display:flex;flex-wrap:wrap;gap:4px}nav .nav-title{display:none}nav a{border-left:0;padding:5px 10px}main{padding:22px 25px}.metrics{gap:10px}.metric strong{font-size:22px}}@media(max-width:560px){header{padding:32px 22px}.metrics{grid-template-columns:repeat(2,1fr)}main{padding:18px 16px}.layout{padding:14px 10px 36px}h2{font-size:20px}.equation{font-size:17px;padding:14px}body{font-size:15px}td,th{padding:9px 10px}}@media print{body{background:white;color:black;font-size:10pt}header{background:white;color:black;padding:12px 0}.hero{max-width:none}.eyebrow,.subhead{color:#444}h1{font-size:24pt}.metric span,.metric strong{color:#222}.layout{display:block;padding:0;max-width:none}nav,.prediction,details,footer{display:none}main{border:0;padding:0}h2{break-after:avoid;margin-top:24px;padding-top:12px}table{font-size:9pt}tr,figure{break-inside:avoid}a{color:inherit}pre{white-space:pre-wrap;color:black;background:#f4f4f4}pre code{white-space:pre-wrap}.table-wrap{overflow:visible}}
'''
nav = '<nav aria-label="报告目录"><p class="nav-title">CONTENTS / 目录</p>'+''.join(f'<a href="#{anchor}">{html.escape(title)}</a>' for title,anchor in sections)+'</nav>'
page = f'''<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content="Week 7 计量经济学:随机扰动项与残差,98 条家庭消费明细的 Stata 回归、数据核对与复现报告。"><title>Week 7|家庭消费回归分析</title><style>{style}</style></head>
<body><header><div class="hero"><div class="eyebrow">ECONOMETRICS · WEEK 07 · 2026.10.23</div><h1>随机扰动、残差<br>与家庭消费回归</h1><p class="subhead">从概念区分到数据核对,用 Stata 估计收入与消费的线性关系。完整呈现原始数据问题、拟合结果与可复现过程。</p><div class="metrics"><div class="metric"><span>有效家庭记录</span><strong>98</strong></div><div class="metric"><span>收入组数</span><strong>10</strong></div><div class="metric"><span>收入系数</span><strong>{model['slope']:.4f}</strong></div><div class="metric"><span>拟合优度 R²</span><strong>{model['r_squared']:.4f}</strong></div></div></div></header><div class="layout">{nav}<main>{''.join(body)}</main></div><footer>Stata/SE 15.1 实际运行 · Python 独立数值核对 · 页面图形与样式全部内嵌,可离线阅读</footer>
<script>
const slider = document.getElementById('income-slider');
slider.addEventListener('input', () => {{
const income = Number(slider.value);
document.getElementById('income-value').textContent = income.toFixed(0);
document.getElementById('pred-value').textContent = ({model['intercept']!r} + {model['slope']!r} * income).toFixed(2);
}});
</script></body></html>'''
(ROOT/'Week7_回归分析报告.html').write_text(page, encoding='utf-8')
# Static checks for complete, portable HTML and working local artifact links.
from html.parser import HTMLParser
class ValidateHTML(HTMLParser):
def handle_starttag(self, tag, attrs):
attrs = dict(attrs)
if tag == 'img':
assert attrs['src'].startswith('data:image/png;base64,')
assert attrs.get('alt')
if tag == 'a' and not attrs['href'].startswith('#'):
assert (ROOT / attrs['href']).exists(), attrs['href']
ValidateHTML().feed(page)
assert '\ufffd' not in page
assert len(re.findall(r'<h2 ', page)) == 7
print(json.dumps({'verification': 'passed', 'records': n, 'report_markdown': str(ROOT/'Week7_回归分析报告.md'), 'report_html': str(ROOT/'Week7_回归分析报告.html'), 'max_abs_fitted_difference': verification['max_abs_fitted_difference']}, ensure_ascii=False, indent=2))
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

+251
View File
@@ -0,0 +1,251 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- This is a Stata 15.1 generated SVG file (http://www.stata.com) -->
<svg version="1.1" width="9.00in" height="6.55in" viewBox="0 0 6480 4716" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<desc>Stata Graph - consumption_fit</desc>
<rect x="0" y="0" width="6480" height="4716" style="fill:#EAF2F3;stroke:none"/>
<rect x="0.00" y="0.00" width="6479.80" height="4716.00" style="fill:#EAF2F3"/>
<rect x="4.72" y="4.72" width="6470.37" height="4706.57" style="fill:none;stroke:#EAF2F3;stroke-width:9.43"/>
<rect x="639.90" y="401.78" width="5674.86" height="3255.92" style="fill:#FFFFFF"/>
<rect x="644.62" y="406.49" width="5665.43" height="3246.49" style="fill:none;stroke:#FFFFFF;stroke-width:9.43"/>
<line x1="639.90" y1="3130.57" x2="6314.76" y2="3130.57" style="stroke:#E1ECEE;stroke-width:14.15"/>
<line x1="639.90" y1="2707.12" x2="6314.76" y2="2707.12" style="stroke:#E1ECEE;stroke-width:14.15"/>
<line x1="639.90" y1="2283.68" x2="6314.76" y2="2283.68" style="stroke:#E1ECEE;stroke-width:14.15"/>
<line x1="639.90" y1="1860.44" x2="6314.76" y2="1860.44" style="stroke:#E1ECEE;stroke-width:14.15"/>
<line x1="639.90" y1="1436.99" x2="6314.76" y2="1436.99" style="stroke:#E1ECEE;stroke-width:14.15"/>
<line x1="639.90" y1="1013.55" x2="6314.76" y2="1013.55" style="stroke:#E1ECEE;stroke-width:14.15"/>
<circle cx="1212.16" cy="3078.93" r="31.58" style="fill:#1A476F"/>
<circle cx="1212.16" cy="3078.93" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1212.16" cy="3050.98" r="31.58" style="fill:#1A476F"/>
<circle cx="1212.16" cy="3050.98" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1212.16" cy="3023.04" r="31.58" style="fill:#1A476F"/>
<circle cx="1212.16" cy="3023.04" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1212.16" cy="3013.72" r="31.58" style="fill:#1A476F"/>
<circle cx="1212.16" cy="3013.72" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1680.75" cy="3013.72" r="31.58" style="fill:#1A476F"/>
<circle cx="1680.75" cy="3013.72" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1680.75" cy="2920.57" r="31.58" style="fill:#1A476F"/>
<circle cx="1680.75" cy="2920.57" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1680.75" cy="2864.67" r="31.58" style="fill:#1A476F"/>
<circle cx="1680.75" cy="2864.67" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1680.75" cy="2836.73" r="31.58" style="fill:#1A476F"/>
<circle cx="1680.75" cy="2836.73" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1680.75" cy="2762.21" r="31.58" style="fill:#1A476F"/>
<circle cx="1680.75" cy="2762.21" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="1680.75" cy="2734.26" r="31.58" style="fill:#1A476F"/>
<circle cx="1680.75" cy="2734.26" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2818.10" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2818.10" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2780.84" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2780.84" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2771.52" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2771.52" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2724.94" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2724.94" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2697.00" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2697.00" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2669.05" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2669.05" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2641.11" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2641.11" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2603.84" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2603.84" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2575.90" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2575.90" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2547.95" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2547.95" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2149.34" cy="2529.32" r="31.58" style="fill:#1A476F"/>
<circle cx="2149.34" cy="2529.32" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2687.68" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2687.68" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2622.48" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2622.48" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2585.21" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2585.21" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2575.90" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2575.90" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2529.32" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2529.32" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2501.38" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2501.38" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2492.06" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2492.06" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2455.00" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2455.00" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2427.06" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2427.06" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2399.11" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2399.11" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2361.85" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2361.85" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2343.22" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2343.22" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="2618.12" cy="2296.64" r="31.58" style="fill:#1A476F"/>
<circle cx="2618.12" cy="2296.64" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2492.06" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2492.06" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2445.69" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2445.69" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2399.11" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2399.11" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2371.16" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2371.16" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2361.85" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2361.85" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2305.96" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2305.96" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2287.32" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2287.32" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2287.32" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2287.32" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2231.43" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2231.43" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2222.12" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2222.12" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2194.17" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2194.17" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2156.91" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2156.91" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3086.71" cy="2101.02" r="31.58" style="fill:#1A476F"/>
<circle cx="3086.71" cy="2101.02" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2361.85" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2361.85" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2324.59" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2324.59" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2240.75" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2240.75" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2203.49" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2203.49" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2156.91" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2156.91" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2138.28" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2138.28" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2128.96" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2128.96" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2101.02" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2101.02" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2073.07" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2073.07" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2054.44" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2054.44" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="2026.49" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="2026.49" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="1970.60" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="1970.60" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="3555.29" cy="1905.40" r="31.58" style="fill:#1A476F"/>
<circle cx="3555.29" cy="1905.40" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="2156.91" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="2156.91" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="2082.39" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="2082.39" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="2073.07" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="2073.07" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="2026.49" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="2026.49" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1989.23" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1989.23" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1961.29" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1961.29" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1924.03" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1924.03" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1886.76" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1886.76" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1849.50" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1849.50" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1830.87" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1830.87" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1774.98" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1774.98" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1765.66" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1765.66" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4023.88" cy="1691.14" r="31.58" style="fill:#1A476F"/>
<circle cx="4023.88" cy="1691.14" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1886.76" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1886.76" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1868.13" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1868.13" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1821.56" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1821.56" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1802.93" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1802.93" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1774.98" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1774.98" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1774.98" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1774.98" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1663.20" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1663.20" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1653.88" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1653.88" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1607.30" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1607.30" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4492.46" cy="1597.99" r="31.58" style="fill:#1A476F"/>
<circle cx="4492.46" cy="1597.99" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1784.30" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1784.30" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1747.03" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1747.03" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1709.77" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1709.77" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1635.25" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1635.25" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1560.73" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1560.73" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1560.73" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1560.73" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1393.05" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1393.05" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1365.10" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1365.10" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="4961.25" cy="1318.53" r="31.58" style="fill:#1A476F"/>
<circle cx="4961.25" cy="1318.53" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="5429.84" cy="1607.30" r="31.58" style="fill:#1A476F"/>
<circle cx="5429.84" cy="1607.30" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="5429.84" cy="1588.67" r="31.58" style="fill:#1A476F"/>
<circle cx="5429.84" cy="1588.67" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="5429.84" cy="1411.68" r="31.58" style="fill:#1A476F"/>
<circle cx="5429.84" cy="1411.68" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="5429.84" cy="1327.84" r="31.58" style="fill:#1A476F"/>
<circle cx="5429.84" cy="1327.84" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="5429.84" cy="1132.22" r="31.58" style="fill:#1A476F"/>
<circle cx="5429.84" cy="1132.22" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<circle cx="5429.84" cy="1132.22" r="31.58" style="fill:#1A476F"/>
<circle cx="5429.84" cy="1132.22" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<line x1="1212.16" y1="3040.86" x2="3321.00" y2="2207.74" stroke-linecap="round" style="stroke:#AE2C33;stroke-width:11.79"/>
<line x1="3321.00" y1="2207.74" x2="5429.84" y2="1374.62" stroke-linecap="round" style="stroke:#AE2C33;stroke-width:11.79"/>
<line x1="639.90" y1="3657.69" x2="639.90" y2="401.78" style="stroke:#000000;stroke-width:9.43"/>
<line x1="639.90" y1="3130.57" x2="574.49" y2="3130.57" style="stroke:#000000;stroke-width:9.43"/>
<text x="492.44" y="3130.57" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" transform="rotate(-90 492.44,3130.57)" text-anchor="middle">500</text>
<line x1="639.90" y1="2707.12" x2="574.49" y2="2707.12" style="stroke:#000000;stroke-width:9.43"/>
<text x="492.44" y="2707.12" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" transform="rotate(-90 492.44,2707.12)" text-anchor="middle">1000</text>
<line x1="639.90" y1="2283.68" x2="574.49" y2="2283.68" style="stroke:#000000;stroke-width:9.43"/>
<text x="492.44" y="2283.68" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" transform="rotate(-90 492.44,2283.68)" text-anchor="middle">1500</text>
<line x1="639.90" y1="1860.44" x2="574.49" y2="1860.44" style="stroke:#000000;stroke-width:9.43"/>
<text x="492.44" y="1860.44" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" transform="rotate(-90 492.44,1860.44)" text-anchor="middle">2000</text>
<line x1="639.90" y1="1436.99" x2="574.49" y2="1436.99" style="stroke:#000000;stroke-width:9.43"/>
<text x="492.44" y="1436.99" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" transform="rotate(-90 492.44,1436.99)" text-anchor="middle">2500</text>
<line x1="639.90" y1="1013.55" x2="574.49" y2="1013.55" style="stroke:#000000;stroke-width:9.43"/>
<text x="492.44" y="1013.55" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" transform="rotate(-90 492.44,1013.55)" text-anchor="middle">3000</text>
<text x="312.21" y="2029.73" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" transform="rotate(-90 312.21,2029.73)" text-anchor="middle">每月消费支出(元)</text>
<line x1="639.90" y1="3657.69" x2="6314.76" y2="3657.69" style="stroke:#000000;stroke-width:9.43"/>
<line x1="1524.62" y1="3657.69" x2="1524.62" y2="3723.10" style="stroke:#000000;stroke-width:9.43"/>
<text x="1524.62" y="3870.49" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" text-anchor="middle">1000</text>
<line x1="2305.66" y1="3657.69" x2="2305.66" y2="3723.10" style="stroke:#000000;stroke-width:9.43"/>
<text x="2305.66" y="3870.49" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" text-anchor="middle">1500</text>
<line x1="3086.71" y1="3657.69" x2="3086.71" y2="3723.10" style="stroke:#000000;stroke-width:9.43"/>
<text x="3086.71" y="3870.49" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" text-anchor="middle">2000</text>
<line x1="3867.75" y1="3657.69" x2="3867.75" y2="3723.10" style="stroke:#000000;stroke-width:9.43"/>
<text x="3867.75" y="3870.49" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" text-anchor="middle">2500</text>
<line x1="4648.79" y1="3657.69" x2="4648.79" y2="3723.10" style="stroke:#000000;stroke-width:9.43"/>
<text x="4648.79" y="3870.49" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" text-anchor="middle">3000</text>
<line x1="5429.84" y1="3657.69" x2="5429.84" y2="3723.10" style="stroke:#000000;stroke-width:9.43"/>
<text x="5429.84" y="3870.49" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" text-anchor="middle">3500</text>
<text x="3477.33" y="4050.52" style="font-family:'Helvetica';font-size:163.82px;fill:#000000" text-anchor="middle">每月可支配收入(元)</text>
<rect x="2002.93" y="4189.07" width="2948.81" height="305.18" style="fill:#FFFFFF"/>
<rect x="2007.64" y="4193.79" width="2939.37" height="295.75" style="fill:none;stroke:#000000;stroke-width:9.43"/>
<circle cx="2098.30" cy="4341.77" r="31.58" style="fill:#1A476F"/>
<circle cx="2098.30" cy="4341.77" r="24.50" style="fill:none;stroke:#1A476F;stroke-width:14.15"/>
<line x1="3052.08" y1="4341.77" x2="3665.05" y2="4341.77" style="stroke:#AE2C33;stroke-width:11.79"/>
<text x="2221.02" y="4399.16" style="font-family:'Helvetica';font-size:163.82px;fill:#000000">consume</text>
<text x="3763.26" y="4399.16" style="font-family:'Helvetica';font-size:163.82px;fill:#000000">Fitted values</text>
<text x="3477.33" y="319.31" style="font-family:'Helvetica';font-size:180.02px;fill:#1A476f" text-anchor="middle">不同可支配收入水平组家庭消费支出的条件分布图</text>
</svg>

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.
Binary file not shown.
+99
View File
@@ -0,0 +1,99 @@
household_id,excel_row,income,consume
1,4,800,561
2,5,800,594
3,6,800,627
4,7,800,638
5,4,1100,638
6,5,1100,748
7,6,1100,814
8,7,1100,847
9,8,1100,935
10,9,1100,968
11,4,1400,869
12,5,1400,913
13,6,1400,924
14,7,1400,979
15,8,1400,1012
16,9,1400,1045
17,10,1400,1078
18,11,1400,1122
19,12,1400,1155
20,13,1400,1188
21,14,1400,1210
22,4,1700,1023
23,5,1700,1100
24,6,1700,1144
25,7,1700,1155
26,8,1700,1210
27,9,1700,1243
28,10,1700,1254
29,11,1700,1298
30,12,1700,1331
31,13,1700,1364
32,14,1700,1408
33,15,1700,1430
34,16,1700,1485
35,4,2000,1254
36,5,2000,1309
37,6,2000,1364
38,7,2000,1397
39,8,2000,1408
40,9,2000,1474
41,10,2000,1496
42,11,2000,1496
43,12,2000,1562
44,13,2000,1573
45,14,2000,1606
46,15,2000,1650
47,16,2000,1716
48,4,2300,1408
49,5,2300,1452
50,6,2300,1551
51,7,2300,1595
52,8,2300,1650
53,9,2300,1672
54,10,2300,1683
55,11,2300,1716
56,12,2300,1749
57,13,2300,1771
58,14,2300,1804
59,15,2300,1870
60,16,2300,1947
61,4,2600,1650
62,5,2600,1738
63,6,2600,1749
64,7,2600,1804
65,8,2600,1848
66,9,2600,1881
67,10,2600,1925
68,11,2600,1969
69,12,2600,2013
70,13,2600,2035
71,14,2600,2101
72,15,2600,2112
73,16,2600,2200
74,4,2900,1969
75,5,2900,1991
76,6,2900,2046
77,7,2900,2068
78,8,2900,2101
79,9,2900,2101
80,10,2900,2233
81,11,2900,2244
82,12,2900,2299
83,13,2900,2310
84,4,3200,2090
85,5,3200,2134
86,6,3200,2178
87,7,3200,2266
88,8,3200,2354
89,9,3200,2354
90,10,3200,2552
91,11,3200,2585
92,12,3200,2640
93,4,3500,2299
94,5,3500,2321
95,6,3500,2530
96,7,3500,2629
97,8,3500,2860
98,9,3500,2860
1 household_id excel_row income consume
2 1 4 800 561
3 2 5 800 594
4 3 6 800 627
5 4 7 800 638
6 5 4 1100 638
7 6 5 1100 748
8 7 6 1100 814
9 8 7 1100 847
10 9 8 1100 935
11 10 9 1100 968
12 11 4 1400 869
13 12 5 1400 913
14 13 6 1400 924
15 14 7 1400 979
16 15 8 1400 1012
17 16 9 1400 1045
18 17 10 1400 1078
19 18 11 1400 1122
20 19 12 1400 1155
21 20 13 1400 1188
22 21 14 1400 1210
23 22 4 1700 1023
24 23 5 1700 1100
25 24 6 1700 1144
26 25 7 1700 1155
27 26 8 1700 1210
28 27 9 1700 1243
29 28 10 1700 1254
30 29 11 1700 1298
31 30 12 1700 1331
32 31 13 1700 1364
33 32 14 1700 1408
34 33 15 1700 1430
35 34 16 1700 1485
36 35 4 2000 1254
37 36 5 2000 1309
38 37 6 2000 1364
39 38 7 2000 1397
40 39 8 2000 1408
41 40 9 2000 1474
42 41 10 2000 1496
43 42 11 2000 1496
44 43 12 2000 1562
45 44 13 2000 1573
46 45 14 2000 1606
47 46 15 2000 1650
48 47 16 2000 1716
49 48 4 2300 1408
50 49 5 2300 1452
51 50 6 2300 1551
52 51 7 2300 1595
53 52 8 2300 1650
54 53 9 2300 1672
55 54 10 2300 1683
56 55 11 2300 1716
57 56 12 2300 1749
58 57 13 2300 1771
59 58 14 2300 1804
60 59 15 2300 1870
61 60 16 2300 1947
62 61 4 2600 1650
63 62 5 2600 1738
64 63 6 2600 1749
65 64 7 2600 1804
66 65 8 2600 1848
67 66 9 2600 1881
68 67 10 2600 1925
69 68 11 2600 1969
70 69 12 2600 2013
71 70 13 2600 2035
72 71 14 2600 2101
73 72 15 2600 2112
74 73 16 2600 2200
75 74 4 2900 1969
76 75 5 2900 1991
77 76 6 2900 2046
78 77 7 2900 2068
79 78 8 2900 2101
80 79 9 2900 2101
81 80 10 2900 2233
82 81 11 2900 2244
83 82 12 2900 2299
84 83 13 2900 2310
85 84 4 3200 2090
86 85 5 3200 2134
87 86 6 3200 2178
88 87 7 3200 2266
89 88 8 3200 2354
90 89 9 3200 2354
91 90 10 3200 2552
92 91 11 3200 2585
93 92 12 3200 2640
94 93 4 3500 2299
95 94 5 3500 2321
96 95 6 3500 2530
97 96 7 3500 2629
98 97 8 3500 2860
99 98 9 3500 2860
+99
View File
@@ -0,0 +1,99 @@
household_id,excel_row,income,consume,_est_OLS,fitted,residual,residual_sq
1,4,800,561,1,605.96992745968,-44.9699274596798,2022.29437572886
2,5,800,594,1,605.96992745968,-11.9699274596798,143.279163389995
3,6,800,627,1,605.96992745968,21.0300725403202,442.263951051132
4,7,800,638,1,605.96992745968,32.0300725403202,1025.92554693818
5,4,1100,638,1,824.609549968307,-186.609549968307,34823.1241393741
6,5,1100,748,1,824.609549968307,-76.6095499683072,5869.02314634656
7,6,1100,814,1,824.609549968307,-10.6095499683072,112.562550530007
8,7,1100,847,1,824.609549968307,22.3904500316928,501.332252621732
9,8,1100,935,1,824.609549968307,110.390450031693,12186.0514581997
10,9,1100,968,1,824.609549968307,143.390450031693,20560.8211602914
11,4,1400,869,1,1043.24917247693,-174.249172476935,30362.7741088966
12,5,1400,913,1,1043.24917247693,-130.249172476935,16964.8469309263
13,6,1400,924,1,1043.24917247693,-119.249172476935,14220.3651364337
14,7,1400,979,1,1043.24917247693,-64.2491724769347,4127.95616397091
15,8,1400,1012,1,1043.24917247693,-31.2491724769347,976.510780493216
16,9,1400,1045,1,1043.24917247693,1.75082752306525,3.06539701552281
17,10,1400,1078,1,1043.24917247693,34.7508275230653,1207.62001353783
18,11,1400,1122,1,1043.24917247693,78.7508275230653,6201.69283556757
19,12,1400,1155,1,1043.24917247693,111.750827523065,12488.2474520899
20,13,1400,1188,1,1043.24917247693,144.750827523065,20952.8020686122
21,14,1400,1210,1,1043.24917247693,166.750827523065,27805.8384796271
22,4,1700,1023,1,1261.88879498556,-238.888794985562,57067.856369654
23,5,1700,1100,1,1261.88879498556,-161.888794985562,26207.9819418774
24,6,1700,1144,1,1261.88879498556,-117.888794985562,13897.7679831479
25,7,1700,1155,1,1261.88879498556,-106.888794985562,11425.2144934656
26,8,1700,1210,1,1261.88879498556,-51.8887949855623,2692.44704505372
27,9,1700,1243,1,1261.88879498556,-18.8887949855623,356.786576006603
28,10,1700,1254,1,1261.88879498556,-7.8887949855623,62.2330863242329
29,11,1700,1298,1,1261.88879498556,36.1112050144377,1304.01912759475
30,12,1700,1331,1,1261.88879498556,69.1112050144377,4776.35865854764
31,13,1700,1364,1,1261.88879498556,102.111205014438,10426.6981895005
32,14,1700,1408,1,1261.88879498556,146.111205014438,21348.484230771
33,15,1700,1430,1,1261.88879498556,168.111205014438,28261.3772514063
34,16,1700,1485,1,1261.88879498556,223.111205014438,49778.6098029944
35,4,2000,1254,1,1480.52841749419,-226.52841749419,51315.123932422
36,5,2000,1309,1,1480.52841749419,-171.52841749419,29421.9980080611
37,6,2000,1364,1,1480.52841749419,-116.52841749419,13578.8720837002
38,7,2000,1397,1,1480.52841749419,-83.5284174941899,6976.99652908368
39,8,2000,1408,1,1480.52841749419,-72.5284174941899,5260.3713442115
40,9,2000,1474,1,1480.52841749419,-6.52841749418985,42.6202349784441
41,10,2000,1496,1,1480.52841749419,15.4715825058101,239.369865234091
42,11,2000,1496,1,1480.52841749419,15.4715825058101,239.369865234091
43,12,2000,1562,1,1480.52841749419,81.4715825058101,6637.61875600103
44,13,2000,1573,1,1480.52841749419,92.4715825058101,8550.99357112885
45,14,2000,1606,1,1480.52841749419,125.47158250581,15743.1180165123
46,15,2000,1650,1,1480.52841749419,169.47158250581,28720.6172770236
47,16,2000,1716,1,1480.52841749419,235.47158250581,55446.8661677906
48,4,2300,1408,1,1699.16804000282,-291.168040002817,84778.8275190821
49,5,2300,1452,1,1699.16804000282,-247.168040002817,61092.0399988342
50,6,2300,1551,1,1699.16804000282,-148.168040002817,21953.7680782764
51,7,2300,1595,1,1699.16804000282,-104.168040002817,10850.9805580285
52,8,2300,1650,1,1699.16804000282,-49.1680400028172,2417.49615771863
53,9,2300,1672,1,1699.16804000282,-27.1680400028172,738.102397594674
54,10,2300,1683,1,1699.16804000282,-16.1680400028172,261.405517532697
55,11,2300,1716,1,1699.16804000282,16.8319599971828,283.314877346763
56,12,2300,1749,1,1699.16804000282,49.8319599971828,2483.22423716083
57,13,2300,1771,1,1699.16804000282,71.8319599971828,5159.83047703687
58,14,2300,1804,1,1699.16804000282,104.831959997183,10989.7398368509
59,15,2300,1870,1,1699.16804000282,170.831959997183,29183.5585564791
60,16,2300,1947,1,1699.16804000282,247.831959997183,61420.6803960452
61,4,2600,1650,1,1917.80766251144,-267.807662511445,71720.9440998439
62,5,2600,1738,1,1917.80766251144,-179.807662511445,32330.7954978296
63,6,2600,1749,1,1917.80766251144,-168.807662511445,28496.0269225778
64,7,2600,1804,1,1917.80766251144,-113.807662511445,12952.1840463189
65,8,2600,1848,1,1917.80766251144,-69.8076625114447,4873.10974531177
66,9,2600,1881,1,1917.80766251144,-36.8076625114447,1354.80401955641
67,10,2600,1925,1,1917.80766251144,7.19233748855527,51.7297185492775
68,11,2600,1969,1,1917.80766251144,51.1923374885553,2620.65541754214
69,12,2600,2013,1,1917.80766251144,95.1923374885553,9061.581116535
70,13,2600,2035,1,1917.80766251144,117.192337488555,13734.0439660314
71,14,2600,2101,1,1917.80766251144,183.192337488555,33559.4325145207
72,15,2600,2112,1,1917.80766251144,194.192337488555,37710.6639392689
73,16,2600,2200,1,1917.80766251144,282.192337488555,79632.5153372547
74,4,2900,1969,1,2136.44728502007,-167.447285020073,28038.5932605935
75,5,2900,1991,1,2136.44728502007,-145.447285020073,21154.9127197103
76,6,2900,2046,1,2136.44728502007,-90.4472850200727,8180.71136750227
77,7,2900,2068,1,2136.44728502007,-68.4472850200727,4685.03082661907
78,8,2900,2101,1,2136.44728502007,-35.4472850200727,1256.51001529427
79,9,2900,2101,1,2136.44728502007,-35.4472850200727,1256.51001529427
80,10,2900,2233,1,2136.44728502007,96.5527149799273,9322.42676999507
81,11,2900,2244,1,2136.44728502007,107.552714979927,11567.5864995535
82,12,2900,2299,1,2136.44728502007,162.552714979927,26423.3851473455
83,13,2900,2310,1,2136.44728502007,173.552714979927,30120.5448769039
84,4,3200,2090,1,2355.0869075287,-265.0869075287,70271.0685431296
85,5,3200,2134,1,2355.0869075287,-221.0869075287,48879.420680604
86,6,3200,2178,1,2355.0869075287,-177.0869075287,31359.7728180784
87,7,3200,2266,1,2355.0869075287,-89.0869075287001,7936.47709302716
88,8,3200,2354,1,2355.0869075287,-1.08690752870007,1.18136797594489
89,9,3200,2354,1,2355.0869075287,-1.08690752870007,1.18136797594489
90,10,3200,2552,1,2355.0869075287,196.9130924713,38774.7659866107
91,11,3200,2585,1,2355.0869075287,229.9130924713,52860.0300897165
92,12,3200,2640,1,2355.0869075287,284.9130924713,81175.4702615595
93,4,3500,2299,1,2573.72653003733,-274.726530037327,75474.6663063506
94,5,3500,2321,1,2573.72653003733,-252.726530037327,63870.6989847081
95,6,3500,2530,1,2573.72653003733,-43.7265300373274,1912.00942910529
96,7,3500,2629,1,2573.72653003733,55.2734699626726,3055.15648171447
97,8,3500,2860,1,2573.72653003733,286.273469962673,81952.4996044692
98,9,3500,2860,1,2573.72653003733,286.273469962673,81952.4996044692
1 household_id excel_row income consume _est_OLS fitted residual residual_sq
2 1 4 800 561 1 605.96992745968 -44.9699274596798 2022.29437572886
3 2 5 800 594 1 605.96992745968 -11.9699274596798 143.279163389995
4 3 6 800 627 1 605.96992745968 21.0300725403202 442.263951051132
5 4 7 800 638 1 605.96992745968 32.0300725403202 1025.92554693818
6 5 4 1100 638 1 824.609549968307 -186.609549968307 34823.1241393741
7 6 5 1100 748 1 824.609549968307 -76.6095499683072 5869.02314634656
8 7 6 1100 814 1 824.609549968307 -10.6095499683072 112.562550530007
9 8 7 1100 847 1 824.609549968307 22.3904500316928 501.332252621732
10 9 8 1100 935 1 824.609549968307 110.390450031693 12186.0514581997
11 10 9 1100 968 1 824.609549968307 143.390450031693 20560.8211602914
12 11 4 1400 869 1 1043.24917247693 -174.249172476935 30362.7741088966
13 12 5 1400 913 1 1043.24917247693 -130.249172476935 16964.8469309263
14 13 6 1400 924 1 1043.24917247693 -119.249172476935 14220.3651364337
15 14 7 1400 979 1 1043.24917247693 -64.2491724769347 4127.95616397091
16 15 8 1400 1012 1 1043.24917247693 -31.2491724769347 976.510780493216
17 16 9 1400 1045 1 1043.24917247693 1.75082752306525 3.06539701552281
18 17 10 1400 1078 1 1043.24917247693 34.7508275230653 1207.62001353783
19 18 11 1400 1122 1 1043.24917247693 78.7508275230653 6201.69283556757
20 19 12 1400 1155 1 1043.24917247693 111.750827523065 12488.2474520899
21 20 13 1400 1188 1 1043.24917247693 144.750827523065 20952.8020686122
22 21 14 1400 1210 1 1043.24917247693 166.750827523065 27805.8384796271
23 22 4 1700 1023 1 1261.88879498556 -238.888794985562 57067.856369654
24 23 5 1700 1100 1 1261.88879498556 -161.888794985562 26207.9819418774
25 24 6 1700 1144 1 1261.88879498556 -117.888794985562 13897.7679831479
26 25 7 1700 1155 1 1261.88879498556 -106.888794985562 11425.2144934656
27 26 8 1700 1210 1 1261.88879498556 -51.8887949855623 2692.44704505372
28 27 9 1700 1243 1 1261.88879498556 -18.8887949855623 356.786576006603
29 28 10 1700 1254 1 1261.88879498556 -7.8887949855623 62.2330863242329
30 29 11 1700 1298 1 1261.88879498556 36.1112050144377 1304.01912759475
31 30 12 1700 1331 1 1261.88879498556 69.1112050144377 4776.35865854764
32 31 13 1700 1364 1 1261.88879498556 102.111205014438 10426.6981895005
33 32 14 1700 1408 1 1261.88879498556 146.111205014438 21348.484230771
34 33 15 1700 1430 1 1261.88879498556 168.111205014438 28261.3772514063
35 34 16 1700 1485 1 1261.88879498556 223.111205014438 49778.6098029944
36 35 4 2000 1254 1 1480.52841749419 -226.52841749419 51315.123932422
37 36 5 2000 1309 1 1480.52841749419 -171.52841749419 29421.9980080611
38 37 6 2000 1364 1 1480.52841749419 -116.52841749419 13578.8720837002
39 38 7 2000 1397 1 1480.52841749419 -83.5284174941899 6976.99652908368
40 39 8 2000 1408 1 1480.52841749419 -72.5284174941899 5260.3713442115
41 40 9 2000 1474 1 1480.52841749419 -6.52841749418985 42.6202349784441
42 41 10 2000 1496 1 1480.52841749419 15.4715825058101 239.369865234091
43 42 11 2000 1496 1 1480.52841749419 15.4715825058101 239.369865234091
44 43 12 2000 1562 1 1480.52841749419 81.4715825058101 6637.61875600103
45 44 13 2000 1573 1 1480.52841749419 92.4715825058101 8550.99357112885
46 45 14 2000 1606 1 1480.52841749419 125.47158250581 15743.1180165123
47 46 15 2000 1650 1 1480.52841749419 169.47158250581 28720.6172770236
48 47 16 2000 1716 1 1480.52841749419 235.47158250581 55446.8661677906
49 48 4 2300 1408 1 1699.16804000282 -291.168040002817 84778.8275190821
50 49 5 2300 1452 1 1699.16804000282 -247.168040002817 61092.0399988342
51 50 6 2300 1551 1 1699.16804000282 -148.168040002817 21953.7680782764
52 51 7 2300 1595 1 1699.16804000282 -104.168040002817 10850.9805580285
53 52 8 2300 1650 1 1699.16804000282 -49.1680400028172 2417.49615771863
54 53 9 2300 1672 1 1699.16804000282 -27.1680400028172 738.102397594674
55 54 10 2300 1683 1 1699.16804000282 -16.1680400028172 261.405517532697
56 55 11 2300 1716 1 1699.16804000282 16.8319599971828 283.314877346763
57 56 12 2300 1749 1 1699.16804000282 49.8319599971828 2483.22423716083
58 57 13 2300 1771 1 1699.16804000282 71.8319599971828 5159.83047703687
59 58 14 2300 1804 1 1699.16804000282 104.831959997183 10989.7398368509
60 59 15 2300 1870 1 1699.16804000282 170.831959997183 29183.5585564791
61 60 16 2300 1947 1 1699.16804000282 247.831959997183 61420.6803960452
62 61 4 2600 1650 1 1917.80766251144 -267.807662511445 71720.9440998439
63 62 5 2600 1738 1 1917.80766251144 -179.807662511445 32330.7954978296
64 63 6 2600 1749 1 1917.80766251144 -168.807662511445 28496.0269225778
65 64 7 2600 1804 1 1917.80766251144 -113.807662511445 12952.1840463189
66 65 8 2600 1848 1 1917.80766251144 -69.8076625114447 4873.10974531177
67 66 9 2600 1881 1 1917.80766251144 -36.8076625114447 1354.80401955641
68 67 10 2600 1925 1 1917.80766251144 7.19233748855527 51.7297185492775
69 68 11 2600 1969 1 1917.80766251144 51.1923374885553 2620.65541754214
70 69 12 2600 2013 1 1917.80766251144 95.1923374885553 9061.581116535
71 70 13 2600 2035 1 1917.80766251144 117.192337488555 13734.0439660314
72 71 14 2600 2101 1 1917.80766251144 183.192337488555 33559.4325145207
73 72 15 2600 2112 1 1917.80766251144 194.192337488555 37710.6639392689
74 73 16 2600 2200 1 1917.80766251144 282.192337488555 79632.5153372547
75 74 4 2900 1969 1 2136.44728502007 -167.447285020073 28038.5932605935
76 75 5 2900 1991 1 2136.44728502007 -145.447285020073 21154.9127197103
77 76 6 2900 2046 1 2136.44728502007 -90.4472850200727 8180.71136750227
78 77 7 2900 2068 1 2136.44728502007 -68.4472850200727 4685.03082661907
79 78 8 2900 2101 1 2136.44728502007 -35.4472850200727 1256.51001529427
80 79 9 2900 2101 1 2136.44728502007 -35.4472850200727 1256.51001529427
81 80 10 2900 2233 1 2136.44728502007 96.5527149799273 9322.42676999507
82 81 11 2900 2244 1 2136.44728502007 107.552714979927 11567.5864995535
83 82 12 2900 2299 1 2136.44728502007 162.552714979927 26423.3851473455
84 83 13 2900 2310 1 2136.44728502007 173.552714979927 30120.5448769039
85 84 4 3200 2090 1 2355.0869075287 -265.0869075287 70271.0685431296
86 85 5 3200 2134 1 2355.0869075287 -221.0869075287 48879.420680604
87 86 6 3200 2178 1 2355.0869075287 -177.0869075287 31359.7728180784
88 87 7 3200 2266 1 2355.0869075287 -89.0869075287001 7936.47709302716
89 88 8 3200 2354 1 2355.0869075287 -1.08690752870007 1.18136797594489
90 89 9 3200 2354 1 2355.0869075287 -1.08690752870007 1.18136797594489
91 90 10 3200 2552 1 2355.0869075287 196.9130924713 38774.7659866107
92 91 11 3200 2585 1 2355.0869075287 229.9130924713 52860.0300897165
93 92 12 3200 2640 1 2355.0869075287 284.9130924713 81175.4702615595
94 93 4 3500 2299 1 2573.72653003733 -274.726530037327 75474.6663063506
95 94 5 3500 2321 1 2573.72653003733 -252.726530037327 63870.6989847081
96 95 6 3500 2530 1 2573.72653003733 -43.7265300373274 1912.00942910529
97 96 7 3500 2629 1 2573.72653003733 55.2734699626726 3055.15648171447
98 97 8 3500 2860 1 2573.72653003733 286.273469962673 81952.4996044692
99 98 9 3500 2860 1 2573.72653003733 286.273469962673 81952.4996044692
+11
View File
@@ -0,0 +1,11 @@
income,n,mean_consume,sd_consume,min_consume,max_consume,fitted_mean,mean_residual
800,4,605,34.7850542618522,561,638,605.96992745968,-.969927459679752
1100,6,825,121.697986836266,638,968,824.609549968307,.390450031692808
1400,11,1045,116.309071013399,869,1210,1043.24917247693,1.75082752306525
1700,13,1265,137.683211273803,1023,1485,1261.88879498556,3.1112050144377
2000,13,1485,135.988357344786,1254,1716,1480.52841749419,4.47158250581015
2300,13,1682.15384615385,154.878902239699,1408,1947,1699.16804000282,-17.014193848971
2600,13,1925,165.183231594493,1650,2200,1917.80766251144,7.19233748855527
2900,10,2136.2,125.612101327858,1969,2310,2136.44728502007,-.247285020072923
3200,9,2350.33333333333,203.425662097976,2090,2640,2355.0869075287,-4.75357419536658
3500,6,2583.16666666667,248.065649912814,2299,2860,2573.72653003733,9.44013662933912
1 income n mean_consume sd_consume min_consume max_consume fitted_mean mean_residual
2 800 4 605 34.7850542618522 561 638 605.96992745968 -.969927459679752
3 1100 6 825 121.697986836266 638 968 824.609549968307 .390450031692808
4 1400 11 1045 116.309071013399 869 1210 1043.24917247693 1.75082752306525
5 1700 13 1265 137.683211273803 1023 1485 1261.88879498556 3.1112050144377
6 2000 13 1485 135.988357344786 1254 1716 1480.52841749419 4.47158250581015
7 2300 13 1682.15384615385 154.878902239699 1408 1947 1699.16804000282 -17.014193848971
8 2600 13 1925 165.183231594493 1650 2200 1917.80766251144 7.19233748855527
9 2900 10 2136.2 125.612101327858 1969 2310 2136.44728502007 -.247285020072923
10 3200 9 2350.33333333333 203.425662097976 2090 2640 2355.0869075287 -4.75357419536658
11 3500 6 2583.16666666667 248.065649912814 2299 2860 2573.72653003733 9.44013662933912
+2
View File
@@ -0,0 +1,2 @@
N,intercept,slope,r_squared,root_mse,rss,F,df_resid,p_F,residual_sum,income_residual_sum,bp_chi2,bp_p
98,22.9309341033397,.728798741695425,.930665682793597,146.627814429752,2063972.7325868,1288.59573654148,96,1.95192337710579e-57,-1.95541360881180e-11,-7.33343767933547e-08,8.70054929702723,.00318114174265192
1 N intercept slope r_squared root_mse rss F df_resid p_F residual_sum income_residual_sum bp_chi2 bp_p
2 98 22.9309341033397 .728798741695425 .930665682793597 146.627814429752 2063972.7325868 1288.59573654148 96 1.95192337710579e-57 -1.95541360881180e-11 -7.33343767933547e-08 8.70054929702723 .00318114174265192
+3
View File
@@ -0,0 +1,3 @@
term,estimate,se,t,p,ci_low,ci_high
income,.728798741695425,.0203024883093348,35.8970157052293,1.95192337710568e-57,.688498620916527,.769098862474323
_cons,22.9309341033397,47.0966291092551,.486891196610789,.627445268846623,-70.5551358041236,116.417004010803
1 term estimate se t p ci_low ci_high
2 income .728798741695425 .0203024883093348 35.8970157052293 1.95192337710568e-57 .688498620916527 .769098862474323
3 _cons 22.9309341033397 47.0966291092551 .486891196610789 .627445268846623 -70.5551358041236 116.417004010803
Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

+3
View File
@@ -0,0 +1,3 @@
term,estimate,se,t,p,ci_low,ci_high
income,.728798741695425,.0214275837158275,34.0121756778903,2.38147366765418e-55,.686265324185673,.771332159205177
_cons,22.9309341033397,43.4475632287272,.527784124108898,.598866968230456,-63.3117972795638,109.173665486243
1 term estimate se t p ci_low ci_high
2 income .728798741695425 .0214275837158275 34.0121756778903 2.38147366765418e-55 .686265324185673 .771332159205177
3 _cons 22.9309341033397 43.4475632287272 .527784124108898 .598866968230456 -63.3117972795638 109.173665486243
+11
View File
@@ -0,0 +1,11 @@
income,n,detail_total,reported_total,difference
800,4,2420,2420,0
1100,6,4950,4950,0
1400,11,11495,11495,0
1700,13,16445,16445,0
2000,13,19305,19305,0
2300,13,21868,23870,-2002
2600,13,25025,25025,0
2900,10,21362,21450,-88
3200,9,21153,21285,-132
3500,6,15499,15510,-11
1 income n detail_total reported_total difference
2 800 4 2420 2420 0
3 1100 6 4950 4950 0
4 1400 11 11495 11495 0
5 1700 13 16445 16445 0
6 2000 13 19305 19305 0
7 2300 13 21868 23870 -2002
8 2600 13 25025 25025 0
9 2900 10 21362 21450 -88
10 3200 9 21153 21285 -132
11 3500 6 15499 15510 -11
+17
View File
@@ -0,0 +1,17 @@
{
"status": "passed",
"date": "2026-10-23",
"observations": 98,
"source_sha256": "d1078e68b6ddfa46e09993228520a62dc5716e4ca1b09d6364bfb4964e794577",
"independent_ols_intercept": 22.9309341033402,
"independent_ols_slope": 0.7287987416954245,
"max_abs_fitted_difference": 4.547473508864641e-12,
"checks": [
"all 98 Excel source records match Stata data, including worksheet row",
"OLS coefficients, fitted values, residuals, R-squared, RMSE",
"conventional and HC1 standard errors and two-sided t-test p-values",
"all income-group counts, means, and source-total differences",
"Stata log completion and no r() errors",
"PNG, SVG, and PDF file structure"
]
}
+165
View File
@@ -0,0 +1,165 @@
version 15.0
clear all
set more off
set type double
set linesize 160
capture log close _all
cd "C:/Users/cattom/Documents/econometrics/Week7"
log using "week7_stata.log", text replace
display "Week 7: household consumption and disposable income"
display "Input: numeric cells C3:L17; row 17 contains reported totals."
import excel using "Eg2_1_1/Eg2_1_1.xlsx", sheet("Sheet1") cellrange(C3:L17) clear
tempname audit
postfile `audit' double income int n double detail_total reported_total difference using "source_totals_audit.dta", replace
local income = 800
foreach col in C D E F G H I J K L {
assert `col'[1] == `income'
quietly summarize `col' in 2/14
local count = r(N)
local total = r(sum)
local reported = `col'[15]
post `audit' (`income') (`count') (`total') (`reported') (`total' - `reported')
rename `col' consume`income'
local income = `income' + 300
}
postclose `audit'
preserve
use "source_totals_audit.dta", clear
list, noobs separator(0)
quietly ds, has(type numeric)
format `r(varlist)' %21.15g
export delimited using "source_totals_audit.csv", datafmt replace
restore
keep in 2/14
generate int excel_row = _n + 3
reshape long consume, i(excel_row) j(income)
drop if missing(consume)
sort income excel_row
generate int household_id = _n
order household_id excel_row income consume
assert _N == 98
assert !missing(income, consume)
label variable income "每月可支配收入(元)"
label variable consume "每月消费支出(元)"
label variable excel_row "Source worksheet row"
label variable household_id "Record identifier"
save "households_clean.dta", replace
quietly ds, has(type numeric)
format `r(varlist)' %21.15g
export delimited using "households_clean.csv", datafmt replace
summarize income consume
regress consume income
estimates store OLS
estimates save "consumption_ols.ster", replace
predict double fitted, xb
predict double residual, residuals
generate double residual_sq = residual^2
scalar slope_ols = _b[income]
scalar intercept_ols = _b[_cons]
scalar rsquared_ols = e(r2)
scalar rmse_ols = e(rmse)
scalar rss_ols = e(rss)
scalar N_ols = e(N)
scalar F_ols = e(F)
scalar df_ols = e(df_r)
scalar pF_ols = Ftail(e(df_m), e(df_r), e(F))
tempname coef
postfile `coef' str12 term double estimate double se double t double p double ci_low double ci_high using "regression_coefficients.dta", replace
foreach term in income _cons {
scalar tval = _b[`term'] / _se[`term']
scalar crit = invttail(e(df_r), .025)
post `coef' ("`term'") (_b[`term']) (_se[`term']) (tval) (2*ttail(e(df_r), abs(tval))) (_b[`term']-crit*_se[`term']) (_b[`term']+crit*_se[`term'])
}
postclose `coef'
preserve
use "regression_coefficients.dta", clear
quietly ds, has(type numeric)
format `r(varlist)' %21.15g
export delimited using "regression_coefficients.csv", datafmt replace
restore
quietly summarize residual, meanonly
scalar residual_sum = r(sum)
generate double income_residual = income * residual
quietly summarize income_residual, meanonly
scalar income_residual_sum = r(sum)
display "Sum of residuals = " %21.12g scalar(residual_sum)
display "Sum of income * residual = " %21.12g scalar(income_residual_sum)
drop income_residual
save "households_fitted.dta", replace
quietly ds, has(type numeric)
format `r(varlist)' %21.15g
export delimited using "households_fitted.csv", datafmt replace
preserve
collapse (count) n=consume (mean) mean_consume=consume (sd) sd_consume=consume (min) min_consume=consume (max) max_consume=consume, by(income)
recast double mean_consume sd_consume
generate double fitted_mean = scalar(intercept_ols) + scalar(slope_ols)*income
generate double mean_residual = mean_consume - fitted_mean
save "income_group_summary.dta", replace
quietly ds, has(type numeric)
format `r(varlist)' %21.15g
export delimited using "income_group_summary.csv", datafmt replace
list, noobs separator(0)
restore
set scheme s2color
graph set window fontface "SimSun"
twoway (scatter consume income, mcolor("26 71 111") msymbol(O) msize(small)) (lfit consume income, lcolor("174 44 51") lwidth(medthin)), title("不同可支配收入水平组家庭消费支出的条件分布图", size(medium) color(navy)) xtitle("每月可支配收入(元)", size(medsmall)) ytitle("每月消费支出(元)", size(medsmall)) xlabel(1000(500)3500) ylabel(500(500)3000, angle(90) grid glcolor("225 236 238")) xscale(range(500 4000)) yscale(range(0 3600)) legend(order(1 "consume" 2 "Fitted values") rows(1) region(lcolor(black) fcolor(white))) graphregion(color("234 242 243")) plotregion(color(white)) xsize(9) ysize(6.55) name(consumption_fit, replace)
graph save "consumption_fit.gph", replace
graph export "consumption_fit.png", width(1800) replace
graph export "consumption_fit.svg", replace
graph export "consumption_fit.pdf", replace
* Heteroskedasticity-robust standard errors as a sensitivity check.
regress consume income, vce(robust)
estimates store Robust
estimates save "consumption_robust.ster", replace
tempname robustcoef
postfile `robustcoef' str12 term double estimate double se double t double p double ci_low double ci_high using "robust_coefficients.dta", replace
foreach term in income _cons {
scalar tval = _b[`term'] / _se[`term']
scalar crit = invttail(e(df_r), .025)
post `robustcoef' ("`term'") (_b[`term']) (_se[`term']) (tval) (2*ttail(e(df_r), abs(tval))) (_b[`term']-crit*_se[`term']) (_b[`term']+crit*_se[`term'])
}
postclose `robustcoef'
preserve
use "robust_coefficients.dta", clear
quietly ds, has(type numeric)
format `r(varlist)' %21.15g
export delimited using "robust_coefficients.csv", datafmt replace
restore
estimates restore OLS
estat hettest
scalar bp_chi2 = r(chi2)
scalar bp_p = r(p)
preserve
clear
set obs 1
generate N = scalar(N_ols)
generate intercept = scalar(intercept_ols)
generate slope = scalar(slope_ols)
generate r_squared = scalar(rsquared_ols)
generate root_mse = scalar(rmse_ols)
generate rss = scalar(rss_ols)
generate F = scalar(F_ols)
generate df_resid = scalar(df_ols)
generate p_F = scalar(pF_ols)
generate residual_sum = scalar(residual_sum)
generate income_residual_sum = scalar(income_residual_sum)
generate bp_chi2 = scalar(bp_chi2)
generate bp_p = scalar(bp_p)
quietly ds, has(type numeric)
format `r(varlist)' %21.15g
export delimited using "model_statistics.csv", datafmt replace
restore
display "WEEK7_ANALYSIS_COMPLETED"
log close
exit, clear