>
<>
syntax [anything(name=detail)]
<>
<>
set linesize 80
<>
# Stata车辆数据文件中车型的重量和油耗之间关系的对比和分析
~~~~
<>
use auto_zh, clear
<>
~~~~
## 检查数据
~~~~
<>
describe 油耗 重量
<>
~~~~
<>
assert 油耗 > 0
<>
~~~~
<>
summarize 重量
<>
~~~~
变量重量的最小值<>,最大值<>,极差<>。
## 用散点图显示油耗与重量关系
~~~~
<>
scatter 油耗 重量, mcolor(blue%50)
<>
~~~~
<>
## 用线性回归研究油耗与重量关系
~~~~
<>
regress 油耗 重量
<>
~~~~
<>
matrix define eb = e(b)
<>
线性回归结果显示重量每增加一百公斤,每百公里油耗增加<>公升。
## 用线性回归结果生成HTML表格
<>
_coef_table, markdown
<>
## 用**estimates table**生成表格
~~~~
<>
quietly regress 油耗 重量 变速比 转弯半径
estimates store 模型1
quietly regress 油耗 重量 变速比 转弯半径 国籍
estimates store 模型2
estimates table 模型1 模型2, b(%7.4f) stats(N r2_a) star
<>
~~~~
<>
estimates table 模型1 模型2, varlabel b(%7.4f) stats(N r2_a) star markdown
<>
## 用**esttab**生成表格
<>
cap erase esttab_ex.html
eststo clear
<>
~~~~
<>
eststo : quietly regress 油耗 重量 变速比 转弯半径
eststo : quietly regress 油耗 重量 变速比 转弯半径 国籍
esttab using esttab_ex.html, label ///
width(80%) nogaps ///
mtitles("模型1" "模型2") ///
title(线性回归结果)
<>
~~~~~
<>
<>
cap erase esttab_ex.html
<>