楼主: fangyuna
1193 11

[面板数据求助] 如何对相同household id的不同个体的某一变量,形成一个新household组合的类别变量? [推广有奖]

11
蓝色 发表于 2023-10-31 21:39:13
如果每个householdID就2行,


* Example generated by -dataex-. For more info, type help dataex
clear
input str10 householdID str12 ID byte ins
"0101041010" "010104101001" 4
"0101041010" "010104101002" 4
"0101041020" "010104102001" 1
"0101041020" "010104102002" 2
"0101041030" "010104103001" 4
"0101041030" "010104103002" 4
"0101041040" "010104104001" 2
"0101041040" "010104104002" 1
"0101041050" "010104105001" 1
"0101041050" "010104105002" 3
end


sort householdID ID ins

tostring ins,gen(ins1)

bysort householdID: gen id=ins1[1]+ins1[2]
list

12
fangyuna 发表于 2023-11-1 22:27:43
蓝色 发表于 2023-10-31 21:39
如果每个householdID就2行,
确实很简单了,谢谢老师指点!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-29 00:00