<> <> syntax [anything(name=detail)] <> <> set linesize 80 <> # Stata车辆数据文件中车型的重量和油耗之间关系的对比和分析 我们希望研究1978车辆数据中两个变量**油耗**和**重量**之间的关系。 ~~~~ <> use auto_zh, clear <> ~~~~ ## 检查数据 首先我们检查**油耗**和**重量**的变量描述和摘要统计数据。 ~~~~ <> describe 油耗 重量 <> ~~~~ <> assert 油耗 > 0 <> ~~~~ <> summarize 油耗 <> ~~~~ 从摘要统计数据看出,变量**油耗**的最小值<>,最大值<>,极差<>。 ~~~~ <> summarize 重量 <> ~~~~ 从摘要统计数据看出,变量**重量**的最小值<>,最大值<>,极差<>。 ## 用散点图显示油耗与重量关系 ~~~~ <> twoway lfitci 油耗 重量 || scatter 油耗 重量, mcolor(%20) scheme(538) <> ~~~~ <> 我们在**油耗**和**重量**的散点图上叠加拟合值与均值的置信区间。 ## 用线性回归研究油耗与重量关系 ~~~~ <> 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 ~~~~ <> 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(线性回归结果) ~~~~~ <> eststo : quietly regress 油耗 重量 变速比 转弯半径 eststo : quietly regress 油耗 重量 变速比 转弯半径 国籍 esttab using esttab_ex.html, label /// width(80%) nogaps /// mtitles("模型1" "模型2") /// title(线性回归结果) <> <> <> cap erase esttab_ex.html <> The community-contributed **esttab** is available on the Boston College Statistical Software Components (SSC) archive; see [ssc install](https://www.stata.com/support/ssc-installation/) for details.