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 文件的开头定义百分位截止点:
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)