qregplot:分位数回归图示-T359

发布时间:2021-04-11 阅读 11189

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

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

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

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

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

⛳ Stata 系列推文:

作者: 李胜胜 (安徽大学)
邮箱: lisheng2@foxmail.com


目录


1. 简介

qregplot可以绘制由各种程序产生分位数回归的系数,包括 qregbsqregsqregmmqregrifhdreg(无条件分位数)。 qregplot 的工作方式与 grqreg 类似,但提供了更多选项,用户可以更好地控制所绘制的图片,还允许使用因子表示法。

该命令的工作原理如下:

  • 步骤 1:收集先前估计的模型的所有信息(例如,通过 qreg 命令估计)。该信息用作估计分布中分位数回归模型的模板。
  • 步骤 2:使用步骤 1 的信息, qregplot 根据与原始模型相同的规格估算 N 个分位数回归,选择将要用于此模型估算的分位数。
  • 步骤 3:一旦所有系数和 CI 被存储, qregplot 将使用 twoway rarea 绘制 CI,并使用 twoway line 绘制点估计值,从而绘制所有请求的系数。每个图片都作为图形(graph)临时存储在内存中。
  • 步骤 3b:如果需要,可在步骤 3 中将 OLS 系数和 CI 添加到每个图形中。
  • 步骤 4:如果请求多个变量进行绘图,则使用图形合并将步骤 3 中的所有绘图合并。

此过程唯一的例外是 sqreg 。 在此命令之后使用时,将从 sqreg 输出中收集系数,而不是重新估计系数。

标准误是根据原始命令估计的。例如,如果首先使用 vce(robust) 估计 qreg ,则 qregplot 将使用相同类型的标准误进行绘图。

由于分位数回归中最耗时的部分是回归本身的估计,特别是如果使用 boostrap 得到标准误,则可以使用选项 estore(name) 请求 qregplot 将所有系数和 CI 存储在内存中。这样做的好处是可以直接使用存储的系数创建图。

在所有情况下,CI 均使用与原始估算相同的置信度(通常为 95%)自动绘制。

2. 理论背景

详见连享会推文

3. qregplot命令

3.1 命令安装

. ssc install qregplot, replace

3.2 语法结构

qregplot [varlist] [, quantiles{cmd:(numlist)
   cons
   ols olsopt(regress options)
   seed(seed number)
   raopt(rarea options)
   lnopt(line options)
   twopt(twoway options)
   grcopt(graph combine options)
   estore(name )
   from(name)
   label labelopt(label options)} ]

选项简介

  • varlist:选择将要绘制图形的变量。如果未提供任何参数,则将绘制除截距以外的所有系数。也可以使用因子表示法。
  • quantiles(numlist):用于绘图的分位数,可以使用任何 numlist 来做到这一点。默认值是分位数(10(5)95)。命令 sqreg 被忽略。
  • cons:绘制截距。
  • ols:要求在图形中包括标准 ols 模型的系数和 CI(通过regress)。
  • olsopt(regress options):用于提供附加信息以通过回归估算模型。例如, olsopt(robust) 请求 OLS 回归以使用稳健性的标准误来估计模型。
  • seed(seed number):如果使用 bsqreg ,则需要设定种子值,以复现同样的结果。
  • raopt(rarea options):提供在图表的“twoway rarea”部分中使用的选项。这可以控制置信区间的各个方面。
  • lnopt(line options):提供在图表的“twoway line”部分中使用的选项。这控制了点估计的各个方面。
  • twopt(twoway options):提供在“twoway”图上使用的选项。结合 rarealine ,它控制图的各个方面。
  • grcopt(graph combine options):提供与“graph combine”一起使用的选项。这控制了所有系数组合图的各个方面。
  • estore(name):要求将所有估计的系数和 CI 保存在 e()中。这将存储在 name 的内存中。以后可以将其仅用于绘制系数图,而无需重新估计分位数回归。
  • from(name):使用先前存储在 e() 中的信息绘制分位数系数。使用此选项时,可以使用一个图形特性选项。
  • label: 将使用变量(或值)标签用作每个分位数图的标题。默认选项是使用变量名。
  • labelopt(options{cmd)}:提供其他信息来处理“长”变量标签。 这两个选项是:
    • lines(#L) 将标签分成 #L 行。
    • maxlength(#k) 将标签分成最大长度为 #k 的行。 如果 #k 太小而无法将标签分成 #L 行,则由行取代。

4. Stata 范例

webuse womenwk,clear

4.1 使用 qreg 的简单条件分位数回归

qreg wage age education i.married children i.county
  1. 绘制所有感兴趣的系数,分位数为 5-95,增量为 2.5。
  1. 与上述相同,但增加了 OLS 系数和 CI
qregplot age education i.married children, q(5(2.5)95) ols
  1. 跨分位数更改 CI 的外观
qregplot age education i.married children, q(5(2.5)95) ols raopt( color(black%5))
  1. 与上述相同,但在组合图中仅绘制 1 列
qregplot age education i.married children, q(5(2.5)95) ols raopt( color(black%5)) grcopt(col(1))
  1. 与上述相同,但更改了图形的外观以提高可读性
qregplot age education i.married children, q(5(2.5)95) ols raopt( color(black%5)) grcopt(col(1) ysize(20) xsize(8))

4.2 使用 bsqreg 估计

bsqreg wage age education i.married children i.county
qregplot age education i.married children, q(5(5)95)

4.3 使用 qrprocess 估计

ssc install qrprocess,replace (if not installed)
qrprocess wage age education i.married children i.county
qregplot age education i.married children, q(5(5)95)

4.4 使用 qreg2 估计

qreg2 wage age education i.married children i.county
qregplot age education i.married children, q(5(5)95)

Note:qreq2需要更新

4.5 使用 ivqreg2 估计

ivqreg2 wage age education married , inst(age education married children)
qregplot age education married , q(5(5)95)

4.6 使用 xtqreq 估计

xtqreg wage age education i.married children , i(county)
qregplot age education i.married children, q(5(5)95)

4.7 使用 mmqreg 估计

mmqreg wage age education i.married children
qregplot age education i.married children, q(5(5)95)

Note:mmqreg最新版本不支持qregplot

4.8 使用 sqreg 估计

set scheme s2color
sqreg wage age education i.married children i.county, q(10 25 50 75 90)
qregplot age education i.married children,

Note:需设置彩色背景才能正常显示。

4.9 使用 mmqreg 估计

rifhdreg wage age education i.married children i.county, rif(q(50))
qregplot age education i.married children, q(5(5)95)

4.10 回归信息存储在内存中绘图

qreg wage age education i.married children i.county, q(50)
qregplot age education i.married children, q(5(5)95) estore(qreg_1)
set scheme s2color
qregplot age education i.married children, from(qreg_1)

4.11 使用标题标签

qregplot age education i.married children, from(qreg_1) label

5. 相关推文

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