# Stata：如何估计置信区间？

Stata连享会   主页 || 视频 || 推文 || 知乎 || Bilibili 站

New！ `lianxh` 命令发布了：

`. ssc install lianxh`

`. help lianxh`

⛳ Stata 系列推文：

## 2. 回归结果中的置信区间

${\beta }_{0}$ 和 ${\beta }_{1}$ 是回归系数也是模型的参数，$\epsilon$ 是误差项。

## 4. Stata 范例

``````. sysuse auto, clear
. des

Observations:            74      1978 automobile data
Variables:            12      13 Apr 2020 17:45
(_dta has notes)
---------------------------------------------------------
Variable      Storage   Display
name         type    format   Variable label
---------------------------------------------------------
make            str18   %-18s     Make and model
price           int     %8.0gc    Price
mpg             int     %8.0g     Mileage (mpg)
rep78           int     %8.0g     Repair record 1978
trunk           int     %8.0g     Trunk space (cu. ft.)
weight          int     %8.0gc    Weight (lbs.)
length          int     %8.0g     Length (in.)
turn            int     %8.0g     Turn circle (ft.)
displacement    int     %8.0g     Displacement (cu. in.)
gear_ratio      float   %6.2f     Gear ratio
foreign         byte    %8.0g     Car origin
----------------------------------------------------------
Sorted by: foreign
``````

``````. ci means  price, level(95)
Variable |  Obs       Mean    Std. err.   [95% conf. interval]
----------+----------------------------------------------------
price |   74   6165.257    342.8719    5481.914      6848.6

. ci proportions foreign
Binomial exact
Variable |  Obs  Proportion   Std. err.   [95% conf. interval]
----------+----------------------------------------------------
foreign |   74    .2972973   .0531331     .196584    .4148353
``````

``````. reg price weight length foreign, level(95)

Source |       SS           df       MS      Number of obs   =        74
---------+----------------------------------   F(3, 70)        =     28.39
Model |   348565467         3   116188489   Prob > F        =    0.0000
Residual |   286499930        70  4092856.14   R-squared       =    0.5489
Total |   635065396        73  8699525.97   Root MSE        =    2023.1
--------------------------------------------------------------------------
price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
---------+----------------------------------------------------------------
weight |      5.775      0.959     6.02   0.000        3.861       7.688
length |    -91.371     32.828    -2.78   0.007     -156.845     -25.897
foreign |   3573.092    639.328     5.59   0.000     2297.992    4848.191
_cons |   4838.021   3742.010     1.29   0.200    -2625.183   12301.224
--------------------------------------------------------------------------
``````

``````. bootstrap, reps(100): reg price weight length foreign //默认reps(50)
(running regress on estimation sample)
Bootstrap replications (100)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
..................................................   100
Linear regression                                Number of obs =        74
Replications  =       100
Wald chi2(3)  =     51.68
Prob > chi2   =    0.0000
R-squared     =    0.5489
Root MSE      = 2023.0809
--------------------------------------------------------------------------
|   Observed   Bootstrap                         Normal-based
price | coefficient  std. err.      z    P>|z|     [95% conf. interval]
---------+----------------------------------------------------------------
weight |      5.775      1.617     3.57   0.000        2.605       8.944
length |    -91.371     54.331    -1.68   0.093     -197.858      15.116
foreign |   3573.092    695.808     5.14   0.000     2209.333    4936.851
_cons |   4838.021   5871.232     0.82   0.410    -6669.382   16345.423
--------------------------------------------------------------------------

. *或者
. reg price weight length foreign, vce(bs, reps(100)) //默认reps(50)
(running regress on estimation sample)
Bootstrap replications (100)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
..................................................   100
Linear regression                                Number of obs =        74
Replications  =       100
Wald chi2(3)  =     59.10
Prob > chi2   =    0.0000
R-squared     =    0.5489
Root MSE      = 2023.0809
--------------------------------------------------------------------------
|   Observed   Bootstrap                         Normal-based
price | coefficient  std. err.      z    P>|z|     [95% conf. interval]
---------+----------------------------------------------------------------
weight |      5.775      1.606     3.59   0.000        2.626       8.923
length |    -91.371     51.877    -1.76   0.078     -193.047      10.306
foreign |   3573.092    640.629     5.58   0.000     2317.481    4828.703
_cons |   4838.021   5365.122     0.90   0.367    -5677.426   15353.467
--------------------------------------------------------------------------
``````

## 6. 参考资料

• What exactly is the confidence interval?
• 何晓群.现代统计分析方法与应用[M].第 3 版.北京：中国人民大学出版社，2012.
• 陈希孺．概争论与数理统计．[M].合肥：中国科学技术大学出版社，1992．
• 盛 骤，谢式千，潘承毅．概概率论与数理统计．[M].第 3 版．北京：高等教育出板社，2006．

## 7. 相关推文

Note：产生如下推文列表的 Stata 命令为：
`lianxh 参数估计 置信区间 bootstrap 统计推断, m`

`ssc install lianxh, replace`

## 相关课程

### 最新课程-直播课

• Note: 部分课程的资料，PPT 等可以前往 连享会-直播课 主页查看，下载。

### 关于我们

• Stata连享会 由中山大学连玉君老师团队创办，定期分享实证分析经验。
• 连享会-主页知乎专栏，400+ 推文，实证分析不再抓狂。直播间 有很多视频课程，可以随时观看。
• 公众号关键词搜索/回复 功能已经上线。大家可以在公众号左下角点击键盘图标，输入简要关键词，以便快速呈现历史推文，获取工具软件和数据下载。常见关键词：`课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法`

✏ 连享会-常见问题解答：
https://gitee.com/lianxh/Course/wikis

New！ `lianxh` 命令发布了：

`. ssc install lianxh`

`. help lianxh`