Используя данные вашего примера:
clear
input str50 ny_address
"8296 Indian Spring St. Hempstead, NY 11550"
"498 Elizabeth St. Bay Shore, NY 11706"
"30 Willow St. Bronx, NY 10461"
"65 Talbot Street New York, NY 10028"
"29 Franklin Rd. New York, NY 10034"
"21 East Gates St. Poughkeepsie, NY 12603"
"26 Wintergreen Ave. Patchogue, NY 11772"
"42 E. Plymouth Street Jackson Heights, NY 11372"
"7887 York Rd. Brooklyn, NY 11221"
"597 St Paul Drive Brooklyn, NY 11236"
"83 SW. Ridgeview Rd. Far Rockaway, NY 11691"
"8447 W. Rose Street Bronx, NY 10472"
"47 N. Carriage Drive Rego Park, NY 11374"
"7953 Rock Maple Street Staten Island, NY 10312"
"7875 East Brook Avenue New York, NY 10024"
"362 Elizabeth St. Staten Island, NY 10314"
"7043 South Sleepy Hollow Street Astoria, NY 11106"
"473 Marshall Court Bronx, NY 10457"
"9283 Albany St. Brooklyn, NY 11209"
end
Если вы устанавливаете пакет с дополнительными функциями для команды egen
:
ssc install egenmore
Вы можете просто сделать следующее:
egen wanted1 = sieve(ny_address), omit(0123456789)
В противном случае простое регулярное выражение поможет:
generate wanted2 = strtrim(ustrregexs(0)) if ustrregexm(ny_address, "([a-zA-Z., ])+")
Оба подхода дают желаемый результат:
list wanted1 wanted2
+-----------------------------------------------------------------------------------+
| wanted1 wanted2 |
|-----------------------------------------------------------------------------------|
1. | Indian Spring St. Hempstead, NY Indian Spring St. Hempstead, NY |
2. | Elizabeth St. Bay Shore, NY Elizabeth St. Bay Shore, NY |
3. | Willow St. Bronx, NY Willow St. Bronx, NY |
4. | Talbot Street New York, NY Talbot Street New York, NY |
5. | Franklin Rd. New York, NY Franklin Rd. New York, NY |
6. | East Gates St. Poughkeepsie, NY East Gates St. Poughkeepsie, NY |
7. | Wintergreen Ave. Patchogue, NY Wintergreen Ave. Patchogue, NY |
8. | E. Plymouth Street Jackson Heights, NY E. Plymouth Street Jackson Heights, NY |
9. | York Rd. Brooklyn, NY York Rd. Brooklyn, NY |
10. | St Paul Drive Brooklyn, NY St Paul Drive Brooklyn, NY |
11. | SW. Ridgeview Rd. Far Rockaway, NY SW. Ridgeview Rd. Far Rockaway, NY |
12. | W. Rose Street Bronx, NY W. Rose Street Bronx, NY |
13. | N. Carriage Drive Rego Park, NY N. Carriage Drive Rego Park, NY |
14. | Rock Maple Street Staten Island, NY Rock Maple Street Staten Island, NY |
15. | East Brook Avenue New York, NY East Brook Avenue New York, NY |
16. | Elizabeth St. Staten Island, NY Elizabeth St. Staten Island, NY |
17. | South Sleepy Hollow Street Astoria, NY South Sleepy Hollow Street Astoria, NY |
18. | Marshall Court Bronx, NY Marshall Court Bronx, NY |
19. | Albany St. Brooklyn, NY Albany St. Brooklyn, NY |
+-----------------------------------------------------------------------------------+