qrprocess：高效好用的分位数回归命令

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

New！ `lianxh` 命令发布了：

`. ssc install lianxh`

`. help lianxh`

⛳ Stata 系列推文：

1. 背景介绍

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.2 安装与语法结构

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

``````. ssc install qrprocess, replace
``````

``````. 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 实例

``````. 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
--------------------------------------------------------------------------
``````

``````. 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
-------------------------------------------------------------------------
``````

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

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–
• Koenker R (2005) Quantile Regression. Cambridge University Press. -Link-PDF-, 有权限的用户可以在线阅读

6. 相关推文

Note：产生如下推文列表的 Stata 命令为：
`lianxh 分位数`

`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`