Hello,
I am working on data that contains both US zip codes and Canadian zip codes that start with letters (truncated to their first five characters). I want to modify my data so that only US zip codes remain, while the foreign ones are dropped. Here is an example:
I tried to run this code, however when it ran it dropped all observations. Is there an efficient way to do it without having to drop each observation manually? I must mention that all the zip codes are strings so that I don't lose zip codes that have leading 0s. Thanks!
I am working on data that contains both US zip codes and Canadian zip codes that start with letters (truncated to their first five characters). I want to modify my data so that only US zip codes remain, while the foreign ones are dropped. Here is an example:
Observation | zip_code |
1 | "12345" |
2 | "58797" |
3 | "L6J 9" |
4 | "K9R 6" |
Code:
drop if zip_code[0] != "0" & zip_code[0] != 1 & [...] & zip_code[0] != 9
Comment