使用权重按年使用 xtile
use xtile by year using weights
我有收入变量和权重的数据,我想按年计算 5% 的分位数。
有办法吗?
对于重量我可以使用常规 xtile
:
xtile quan = salary [aw=weight], n(20)
多年来我可以使用 egenmore
中的 xtile
:
egen quan = xtile(salary), by(year) nq(20)
但是我怎样才能计算重量和按年一起计算呢?
有一个weights()
选项,如help egenmore
所述:
clear
set more off
sysuse auto
keep mpg foreign weight
// egenmore
egen mpg4 = xtile(mpg), by(foreign) nq(4) weights(weight)
// compare with xtile
xtile mpg4_1 = mpg [aweight=weight] if foreign, nq(4)
xtile mpg4_2= mpg [aweight=weight] if !foreign, nq(4)
egen mpg42 = rowtotal(mpg4_1 mpg4_2)
assert mpg4 == mpg42
sort foreign mpg weight
list, sepby(foreign)
在 egen
的 xtile
函数的 ado 文件中,您可以检查权重是如何设置的:
if "`weights'" ~= "" {
local weight "[aw = `weights']"
}
参见 viewsource _gxtile.ado
。
我有收入变量和权重的数据,我想按年计算 5% 的分位数。 有办法吗?
对于重量我可以使用常规 xtile
:
xtile quan = salary [aw=weight], n(20)
多年来我可以使用 egenmore
中的 xtile
:
egen quan = xtile(salary), by(year) nq(20)
但是我怎样才能计算重量和按年一起计算呢?
有一个weights()
选项,如help egenmore
所述:
clear
set more off
sysuse auto
keep mpg foreign weight
// egenmore
egen mpg4 = xtile(mpg), by(foreign) nq(4) weights(weight)
// compare with xtile
xtile mpg4_1 = mpg [aweight=weight] if foreign, nq(4)
xtile mpg4_2= mpg [aweight=weight] if !foreign, nq(4)
egen mpg42 = rowtotal(mpg4_1 mpg4_2)
assert mpg4 == mpg42
sort foreign mpg weight
list, sepby(foreign)
在 egen
的 xtile
函数的 ado 文件中,您可以检查权重是如何设置的:
if "`weights'" ~= "" {
local weight "[aw = `weights']"
}
参见 viewsource _gxtile.ado
。