【问题标题】:Regressing on percentile stata回归百分位数
【发布时间】:2015-11-17 07:20:35
【问题描述】:

有谁知道是否有更好的方法来回归前 25% 最富有的女性?我的代码首先找到 25% 最富有女性的收入截止值,然后在回归中的 if 子句中硬编码数字。是否可以在if 子句中编码百分位数,这样如果我更改数据集就不必检查和调整硬编码部分?

这是我的代码。

/*
Predict medical expenditures for the 25 % richest females 
with and without supplementary expenditures
*/

centile(income) if female == 1, centile(25,75)
regress ltotexp suppins phylim actlim totchr age female income if female == 1 & income > 24, vce(robust)

【问题讨论】:

    标签: regression stata


    【解决方案1】:

    Stata 将其许多命令的结果存储在r()(和e())中。请参阅help r[U] 18.8 Accessing results calculated by other programs,并注意许多命令帮助文件底部的部分,说明哪些结果存储在r() 中。例如centilehelp centile 状态:

    centile stores the following in r():
    
    Scalars   
      r(N)           number of observations
      r(n_cent)      number of centiles requested
      r(c_#)         value of # centile
      r(lb_#)        #-requested centile lower confidence bound
      r(ub_#)        #-requested centile upper confidence bound
    

    所以一种选择是(使用系统数据集):

    sysuse auto , clear
    
    // using centile
    centile price if foreign , centile(25 75)
    local pctile = r(c_2)
    regress mpg weight if foreign & price > `pctile' , vce(robust)
    

    但是,更清晰的选择是从summarize 访问百分位数:

    sysuse auto , clear
    
    // using summarize
    summarize price if foreign , detail
    local pctile = r(p75)
    regress mpg weight if foreign & price > `pctile' , vce(robust)
    

    如果需要,将结果存储在 localpctile 中允许您稍后参考它。

    您甚至可以更进一步,在您的 do 文件的开头定义百分位截止点:

    local pctilecutoff = 75
    sysuse auto , clear
    
    // using summarize
    summarize price if foreign , detail
    local pctile = r(p`pctilecutoff')
    regress mpg weight if foreign & price > `pctile' , vce(robust)
    

    【讨论】:

    • 这很有帮助,但在存储本地宏的保存结果时可能会导致非常小的精度损失。您可以通过直接使用(例如) `=r(p75)' 调用保存的结果来避免该步骤,
    • 优秀的答案布伦丹!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 2020-12-24
    • 2020-05-28
    • 2012-11-28
    • 2011-09-07
    • 2020-08-26
    • 2019-03-20
    相关资源
    最近更新 更多