为同一观察匹配不同的变量

Matching different variables for the same observation

我在使用 Stata 分析数据集时遇到了一些困难。我的数据集是以下形式的重复横截面:

Individual Year Age VarA VarB VarC

已使用 egen 命令按年份为每个人计算变量 C。因此,这个变量是特定于年份的。我现在想匹配这个变量的值对应于每个人 x 岁时的年份。 (我通过变换变量 D=Year-Age+x 创建了这个新变量)。 我想为每个人匹配 "variableD" 年获得的变量 C 的值。

下面是如何使用用户编写的 xfill:

执行此操作的示例
net install xfill, from("http://www.sealedenvelope.com/")
webuse nlswork, clear
duplicates drop idcode age, force
gen x=20 if mod(idcode,2)==1
replace x=25 if mod(idcode,2)!=1
bys idcode year: egen var_c = mean(ln_wage)

bys idcode: gen var_c_at_x = var_c if age == x
xfill var_c_at_x, i(idcode)

edit idcode ln_wage year age x var_c*