Keeping all the records for specific IDs
问题 I have the following dataset: 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 I want to get the output below: id code cost 1 15342 18 2 15366 12 1 16786 32 2 15342 12 1 34234 23 2 22223 12 1 23432 22 I tried to use this command but it did not work: keep if id = (1|2) How can I keep all the records for specific IDs? 回答1: The following works for me: keep if id == 1 | id == 2 Alternatively, you