分享

qregplot:分位数回归图示

 安三六 2022-02-26

👇 连享会 · 推文导航 | www.lianxh.cn

Image
Image

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


目录

  • 1. 简介

  • 2. 理论背景

  • 3. `qregplot`命令

    • 3.1 命令安装

    • 3.2 语法结构

  • 4. Stata 范例

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

    • 4.2 使用 `bsqreg` 估计

    • 4.3 使用 `qrprocess` 估计

    • 4.4 使用 `qreg2` 估计

    • 4.5 使用 `ivqreg2` 估计

    • 4.6 使用 `xtqreq` 估计

    • 4.7 使用 `mmqreg` 估计

    • 4.8 使用 `sqreg` 估计

    • 4.9 使用 `mmqreg` 估计

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

    • 4.11 使用标题标签

  • 5.  相关推文


温馨提示: 文中链接在微信中无法生效。请点击底部「阅读原文」。或直接长按/扫描如下二维码,直达原文:

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。
Image
  1. 与上述相同,但增加了 OLS 系数和 CI
qregplot age education i.married children, q(5(2.5)95) ols
Image
  1. 跨分位数更改 CI 的外观
qregplot age education i.married children, q(5(2.5)95) ols raopt( color(black%5))
Image
  1. 与上述相同,但在组合图中仅绘制 1 列
qregplot age education i.married children, q(5(2.5)95) ols raopt( color(black%5)) grcopt(col(1))
Image
  1. 与上述相同,但更改了图形的外观以提高可读性
qregplot age education i.married children, q(5(2.5)95) ols raopt( color(black%5)) grcopt(col(1) ysize(20) xsize(8))
Image
Image

4.2 使用 bsqreg 估计

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

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)
Image

4.4 使用 qreg2 估计

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

Note:qreq2需要更新Image

4.5 使用 ivqreg2 估计

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

4.6 使用 xtqreq 估计

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

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:需设置彩色背景才能正常显示。Image

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)
Image

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
Image

5.  相关推文

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

  • 专题:回归分析
    • Stata R:分位数回归一文读懂
    • Stata:分位数回归简介
  • 专题:内生性-因果推断
    • Stata:分位数回归中的样本自选择问题
  • 专题:分位数回归
    • Stata:面板分位数模型估计及内生性初探
Image
Image

New! Stata 搜索神器:lianxhsongbl  GIF 动图介绍
搜: 推文、数据分享、期刊论文、重现代码 ……
👉 安装:
. ssc install lianxh
. ssc install songbl
👉  使用:
. lianxh DID 倍分法
. songbl all

Image

🍏 关于我们

  • 连享会 ( www.lianxh.cn,推文列表) 由中山大学连玉君老师团队创办,定期分享实证分析经验。
  • 直通车: 👉【百度一下:连享会】即可直达连享会主页。亦可进一步添加 「知乎」,「b 站」,「面板数据」,「公开课」 等关键词细化搜索。
Image

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多