使用特定代码保留所有ID的所有记录

时间:2019-09-10 18:24:47

标签: stata

请考虑以下数据示例:

font.pointSize

如何在任何行中保留包含代码clear input id code cost 1 15342 18 2 15366 12 1 16786 32 2 15342 12 3 12345 45 4 23453 345 1 34234 23 2 22223 12 4 22342 64 3 23452 23 1 23432 22 end 的ID的所有记录?

这是我的上一个Keeping all the records for specific IDs

的后续问题

1 个答案:

答案 0 :(得分:2)

以下对我有用:

id

结果:

clear

input id code cost
1 15342 18
2 15366 12
1 16786 32
2 15342 12
3 12345 45
4 23453 345
1 34234 23
2 22223 12
4 15342 64
3 23452 23
1 23432 22
end

bysort id (code): egen tag = total(inlist(code, 15342))
keep if tag

请注意,为更好地说明,我稍稍更改了数据示例。