qrprocess:高效好用的分位数回归命令-T313

发布时间:2021-06-10 阅读 4099

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

温馨提示: 定期 清理浏览器缓存,可以获得最佳浏览体验。

New! lianxh 命令发布了:
随时搜索推文、Stata 资源。安装:
. ssc install lianxh
详情参见帮助文件 (有惊喜):
. help lianxh

课程详情 https://gitee.com/lianxh/Course

课程主页 https://gitee.com/lianxh/Course

⛳ Stata 系列推文:

PDF下载 - 推文合集

作者:赵玉 (山东大学)
邮箱zhaoyu_yep@163.com


目录


1. 背景介绍

在连享会以往的推文中,我们介绍了分位数回归的基本方法(具体链接链接见「6. 相关推文」),包括总体分位数,样本分位数以及面板分位数回归模型。

分位数方法之所以被广泛使用,关键取决于快速算法的存在。尽管在算法上目前已有很多改进,但计算时间仍然是不可忽略的。本文主要向大家介绍一种分位数回归命令 qrprocess,这一命令与 Stata 官方命令 qreg 的估计结果相近,但运算速度约为前者的 30 倍。

引述一段 Chernozhukov, V., I. Fernández-Val, and B. Melly. 2020a. Fast algorithms for the quantile regression process. Working paper. -PDF- 在结论部分的观点:

Instead of bootstrapping the quantile regression estimates, it is possible to bootstrap the score (or estimating equation) of the estimator. This approach amounts in fact to using the one-step estimator to compute the bootstrap estimate when we take the sample estimate as a preliminary guess. This inference procedure, which has been suggested for quantile regression by Chernozhukov and Hansen (2006) and Belloni et al. (2017), is extremely fast and can also be used to perform uniform inference. Its drawback is the necessity to choose a smoothing parameter to estimate the conditional density of the response variable given the covariates.

The simulations we report in Section 6 show that the preprocessing algorithm is 30 times faster than Stata’s built-in algorithm when we have 50, 000 observations, 20 regressors and we estimate 99 quantile regressions. The onestep estimator further divides the computing time by almost 4. The preprocessing step applied to the bootstrap of a single quantile regression divides the computing time by about 10. The score multiplier bootstrap further divides the computing time by 10 compared to the preprocessing algorithm. Thus, these new algorithms open new possibilities for quantile regression methods. For instance, in the application reported in Section 7, we could estimate 91 different quantile regressions in a sample of 2, 194, 021 observations, with 14 regressors and bootstrap 100 times the estimates in about 30 minutes on a laptop. The same estimation with the built-in commands of Stata would take over two months. The codes in Stata and some rudimentary codes in R are available from the authors.

2. qrprocess 命令介绍

2.1 理论介绍

令 (yi,xi) 为 {Y,X} 的随机样本,Bassett and Koenker (1978) 的分位数回归估计量为:

其中,bRk 为系数向量,ρτ 为线性损失函数,对 τ,τ(0,1)。 此公式为最基础的公式,当然还存在一系列的改进模型,如 Chernozhukov, Fernández-Val and Melly (2020a) 提供了新的算法,有关 Stata 命令的更多详细信息请参照 Fernández-Val and Melly (2020b)。

2.2 安装与语法结构

qrprocess 命令是 Chernozhukov, Fernández-Val and Melly (2020) 编写的 Stata 新命令,安装命令如下:

. ssc install qrprocess, replace

该命令依赖于 moremata,需预先安装:

. ssc install moremata, replace

如果无法直接安装,可以使用如下推文中介绍的手动安装方法:

亦可直接执行如下命令:

. net install moremata, from(https://file.lianxh.cn/StataCMD/moremata) replace force

qrprocess 命令语法结构如下:

. help qrprocess
. qrprocess depvar [indepvars] [if] [in] [weight] [, options]

. depvar:被解释变量;
. indepvars:解释变量;
. Options:
  . quantile(numlist):指定要估计的分位数;默认值为0.5(中位数)
  . method([mtype], [mopts]):指定用于计算分位数回归估计的算法方法以及控制算法结束的参数
  . vce([vtype], [vopts]):指定用于估计标准误差
  . functional:提供置信区间、假设检验
  . level(#):设置置信水平;默认值为水平为0.95
  . noprint:禁止显示结果

3. Stata 实例

我们使用 qrprocess 命令来实现分位数回归模型,这里我们使用 Stata 自带的数据 auto.dta。

首先进行中位数回归:

. sysuse auto, clear

. qrprocess price mpg weight length foreign // 中位数回归

Quantile regression
No. of obs.        74
Algorithm:         qreg.
Variance:          kernel estimate of the sandwich as proposed by Powell(1990).

--------------------------------------------------------------------------
price	Coef.	        Std. Err.	t	P>t    [95% Conf.	Interval]
--------------------------------------------------------------------------
Quant. 0.5
mpg	6.297878	134.9509	0.05	0.963	-262.9217	275.5175
weight	3.933588	2.487104	1.58	0.118	-1.026785	8.893961
length -41.25191	72.577	        -0.57	0.572	-186.0022	103.4984
foreign	3377.771	1411.45	        2.39	0.019	 562.7222	6192.82
_cons	344.6489	7452.584	0.05	0.963	-14519.06	15208.36
--------------------------------------------------------------------------

有上述结果可知,mpg 每增加一单位,会使价格中位数增加 6.30 个单位,即当汽车每加仑能行走的公里数提高一个单位,中档价位的汽车便会增加 6.30 个单位,但统计结果上并不显著。

进一步地,用 bootstrap 标准误差估计 0.25、0.5、0.75 分位点上的回归结果:

. qrprocess price mpg weight length foreign, vce(boot) quantile(0.25 0.5 0.75)
(bootstrapping .......................)

Quantile regression
No. of obs.        74
Algorithm:         qreg.
Variance:          empirical bootstrap.



-------------------------------------------------------------------------
price	Coef.	        Std. Err.	t	P>t    [95% Conf.	Interval]
-------------------------------------------------------------------------
Quant. 0.25
mpg	 6.85905	54.47329	0.13	0.900	-101.8122	115.5303
weight	1.903734	1.398422	1.36	0.178	-.8860422	4.69351
length	2.037834	27.91324	0.07	0.942	-53.64756	57.72323
foreign	2253.604	935.7526	2.41	0.019	386.8291	4120.38
_cons	-2097.658	3569.829	-0.59	0.559	-9219.271	5023.956
-------------------------------------------------------------------------
Quant. 0.5
mpg	6.297878	134.9509	0.05	0.963	-262.9217	275.5175
weight	3.933588	2.487104	1.58	0.118	-1.026785	8.893961
length -41.25191	72.577	        -0.57	0.572	-186.0022	103.4984
foreign	3377.771	1411.45	        2.39	0.019	 562.7222	6192.82
_cons	344.6489	7452.584	0.05	0.963	-14519.06	15208.36
-------------------------------------------------------------------------
Quant. 0.75
mpg	-47.17156	166.7631	-0.28	0.778	-379.8547	285.5116
weight	9.139458	2.530752	3.61	0.001	4.090746	14.18817
length	-226.8545	85.49465	-2.65	0.010	-397.4116	-56.2973
foreign	3343.127	1130.874	2.96	0.004	1087.096	5599.159
_cons	22606.38	12346.16	1.83	0.071	-2023.526	47236.29
-------------------------------------------------------------------------

估计 0.1,0.2,…,0.9 分位数的离散分位数回归过程,并绘制所有系数:

. qrprocess price mpg weight length foreign, quantile(0.1(0.01)0.9) noprint
. plotprocess

4. 结语

关于 qrprocess 的基本介绍在这里就结束了,想要深入了解的学者可以阅读下方的参考资料,或者 help qrprocess 查看相关命令的应用与介绍。

5. 参考资料

  • Angrist J, Chernozhukov V, Fern´andez-Val I (2006) Quantile regression under misspecification, with an application to the us wage structure. Econometrica 74: 539–563. -PDF-
  • Bassett, Gilbert, and Roger Koenker. 1978. “Asymptotic Theory of Least Absolute Error Regression.” Journal of the American Statistical Association 73 (363): 618–22. -PDF-
  • Chernozhukov, V., I. Fernández-Val, and B. Melly. 2020a. Fast algorithms for the quantile regression process. Working paper. -PDF-
  • Chernozhukov, V., I. Fernández-Val, and B. Melly. 2020b. Quantile and distribution regression in Stata: algorithms, pointwise and functional inference. Working paper.
  • Chernozhukov V, Hansen C (2006) Instrumental quantile regression inference for structural and treatment effect models. Journal of Econometrics 132:491–
  1. -PDF-
  • Koenker R (2005) Quantile Regression. Cambridge University Press. -Link-PDF-, 有权限的用户可以在线阅读

6. 相关推文

Note:产生如下推文列表的 Stata 命令为:
lianxh 分位数
安装最新版 lianxh 命令:
ssc install lianxh, replace

相关课程

免费公开课

最新课程-直播课

专题 嘉宾 直播/回看视频
最新专题 文本分析、机器学习、效率专题、生存分析等
研究设计 连玉君 我的特斯拉-实证研究设计-幻灯片-
面板模型 连玉君 动态面板模型-幻灯片-
面板模型 连玉君 直击面板数据模型 [免费公开课,2小时]
  • Note: 部分课程的资料,PPT 等可以前往 连享会-直播课 主页查看,下载。

课程主页

课程主页

关于我们

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

连享会小程序:扫一扫,看推文,看视频……

扫码加入连享会微信群,提问交流更方便

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

New! lianxh 命令发布了:
随时搜索连享会推文、Stata 资源,安装命令如下:
. ssc install lianxh
使用详情参见帮助文件 (有惊喜):
. help lianxh