# Stata：分位数回归简介

Stata 连享会   主页 || 视频 || 推文

Email: ht_wu@foxmail.com

## 2 分位数回归模型

### 2.3 分位数估计方法

${\rho }_{\tau }\left(u\right)=\left\{\begin{array}{ll}\tau u,& u\ge 0\\ \left(\tau -1\right)u,& u<0\end{array}$

## 3 Stata 范例

``````. sysuse "auto.dta", clear
(1978 Automobile Data)

. qreg price mpg rep78 headroom trunk weight length
Iteration  1:  WLS sum of weighted deviations =  54582.043
…… (output omitted)
Iteration  6: sum of abs. weighted deviations =  52754.926

Median regression                                   Number of obs =         69
Raw sum of deviations    65163 (about 5079)
Min sum of deviations 52754.93                    Pseudo R2     =     0.1904

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -20.44398   100.1651    -0.20   0.839    -220.6711    179.7831
rep78 |   766.3722   380.1109     2.02   0.048     6.541433    1526.203
headroom |  -527.2818   525.7287    -1.00   0.320    -1578.199     523.635
trunk |   108.3175   131.2516     0.83   0.412    -154.0507    370.6857
weight |   4.197336   1.385672     3.03   0.004     1.427417    6.967255
length |  -88.23944   51.85082    -1.70   0.094    -191.8878    15.40887
_cons |   7474.973   7400.575     1.01   0.316    -7318.566    22268.51
-----------------------------------------------------------------------------```
``````

``````. set seed 10000  // 设定种子值
. bsqreg price mpg rep78 headroom trunk weight length, reps(400) q(0.5)
(fitting base model)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
................. (output omitted)
..................................................   400

Median regression, bootstrap(400) SEs               Number of obs =         69
Raw sum of deviations    65163 (about 5079)
Min sum of deviations 52754.93                    Pseudo R2     =     0.1904

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -20.44398   87.80782    -0.23   0.817    -195.9693    155.0814
rep78 |   766.3722   414.1785     1.85   0.069    -61.55878    1594.303
headroom |  -527.2818   341.1344    -1.55   0.127      -1209.2    154.6362
trunk |   108.3175   99.74076     1.09   0.282    -91.06144    307.6964
weight |   4.197336   3.256015     1.29   0.202    -2.311345    10.70602
length |  -88.23944    90.8892    -0.97   0.335    -269.9244    93.44548
_cons |   7474.973   8075.536     0.93   0.358    -8667.793    23617.74
-----------------------------------------------------------------------------
``````

``````. sqreg price mpg rep78 headroom trunk weight length, q(0.25 0.5 0.75) reps(400)
(fitting base model)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
(output omitted)
..................................................   400

Simultaneous quantile regression                    Number of obs =         69
bootstrap(400) SEs                                .25 Pseudo R2 =     0.1953
.50 Pseudo R2 =     0.1904
.75 Pseudo R2 =     0.3665

------------------------------------------------------------------------------
|              Bootstrap
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
q25          |
mpg |  -58.85941    60.6889    -0.97   0.336    -180.1748    62.45596
rep78 |   378.5492   182.5255     2.07   0.042     13.68592    743.4125
headroom |  -428.4049   177.6041    -2.41   0.019    -783.4304   -73.37946
trunk |   157.9781   53.96136     2.93   0.005     50.11082    265.8453
weight |   .8091042   1.739727     0.47   0.644    -2.668561     4.28677
length |  -24.49825   47.20241    -0.52   0.606    -118.8545    69.85801
_cons |   5805.491   4010.312     1.45   0.153    -2211.008    13821.99
-------------+----------------------------------------------------------------
q50          |
mpg |  -20.44398   98.12396    -0.21   0.836     -216.591     175.703
rep78 |   766.3722   410.5124     1.87   0.067    -54.23035    1586.975
headroom |  -527.2818   316.1929    -1.67   0.100    -1159.342    104.7788
trunk |   108.3175   100.5004     1.08   0.285    -92.57998     309.215
weight |   4.197336   3.346488     1.25   0.214    -2.492198    10.88687
length |  -88.23944   93.76858    -0.94   0.350    -275.6802    99.20127
_cons |   7474.973   8158.464     0.92   0.363    -8833.564    23783.51
-------------+----------------------------------------------------------------
q75          |
mpg |  -158.3163   115.8176    -1.37   0.177    -389.8324    73.19971
rep78 |   1453.687   447.9351     3.25   0.002     558.2771    2349.096
headroom |  -837.2497   580.2633    -1.44   0.154     -1997.18    322.6801
trunk |   90.09523   136.9239     0.66   0.513    -183.6118    363.8023
weight |   7.364424   2.936931     2.51   0.015     1.493583    13.23527
length |  -185.4982   95.92216    -1.93   0.058    -377.2439    6.247448
_cons |   19508.66   10929.18     1.79   0.079    -2338.458    41355.77
-----------------------------------------------------------------------------```
``````

``````.  qui bsqreg price mpg rep78 headroom trunk weight length,reps(400) q(0.5)
.  qrqreg, cons ci ols olci
``````

## 参考资料

Source[1]：分位数回归理论及其应用」 「Source[2]：高级计量经济学及Stata应用」 「Source[3]：分位数回归及应用简介

## 相关课程

http://lianxh.duanshu.com

### 课程一览

Stata数据清洗 游万海 直播, 2 小时，已上线

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

#### 关于我们

• Stata连享会 由中山大学连玉君老师团队创办，定期分享实证分析经验。直播间 有很多视频课程，可以随时观看。
• 连享会-主页知乎专栏，300+ 推文，实证分析不再抓狂。
• 公众号推文分类： 计量专题 | 分类推文 | 资源工具。推文分成 内生性 | 空间计量 | 时序面板 | 结果输出 | 交乘调节 五类，主流方法介绍一目了然：DID, RDD, IV, GMM, FE, Probit 等。
• 公众号关键词搜索/回复 功能已经上线。大家可以在公众号左下角点击键盘图标，输入简要关键词，以便快速呈现历史推文，获取工具软件和数据下载。常见关键词：`课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法`

✏ 连享会学习群-常见问题解答汇总：
https://gitee.com/arlionn/WD