百分位统计回归

Regressing on percentile stata

有谁知道是否有更好的方法来回归前 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)

Stata 将其许多命令的结果存储在 r()(和 e())中。请参阅 help r[U] 18.8 Accessing results calculated by other programs,并注意许多命令帮助文件底部的部分说明了哪些结果存储在 r() 中。例如,在 centile 的情况下,help 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)

将结果存储在 local 宏中 pctile 允许您以后在需要时引用它。

您甚至可以更进一步,在您的 do-file 的开头定义百分位数截止值:

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)