stata数据处理——分位数分组的命令
分位数分组的命令:
| pctile |
、xtile、astile
1.-pctile- 命令
sysuse auto, clear
pctile p_price = price, nq(10) // nq(#) 指定分9个百分位数,把样本切割为10组
list p_price in 1/12, sep(0)
pctile p_price2 = price, nq(10) gen(percent) // gen() 选项用于生成对应的百分位标识
list percent p_price2 in 1/12, sep(0)
2. -xtile- 命令 // 根据指定的百分位数定义类别变量,例如把25%定义为1,50%定义为2等等。
xtile x_bp = bp, nq(4)
list, sepby(x_bp)
3. astile
案例1:根据公司的市场价值创建10个分组
astile size10 = mvalue, nq(10)
astile
比 state 官方提供的
xtile
命令处理速度更快。 它的高效性在数据集较大或者当分组类别被多次创建时更加明显,比如说,我们可能需要根据每个年份或者月份分别创建分组。