Hi,
I am trying to "standardise" my variable prim_state to two letters only. It contains names of both individual and multiple states. If it is a latter case, I want to reduce the variable value to the name of the first state only. For example reduce the observation "OH-KY-IN" to "OH"
I am not sure how to use levelsof, foreach loop, string length and replace command to set this up. Any help would be highly recommended. Thank you.
I am trying to "standardise" my variable prim_state to two letters only. It contains names of both individual and multiple states. If it is a latter case, I want to reduce the variable value to the name of the first state only. For example reduce the observation "OH-KY-IN" to "OH"
I am not sure how to use levelsof, foreach loop, string length and replace command to set this up. Any help would be highly recommended. Thank you.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str11 prim_state "TX" "OH" "GA" "OR" "NY" "NM" "LA" "PA-NJ" "PA" "TX" "IA" "AK" "MI" "AL" "WI" "NC" "GA" "GA" "NJ" "AL" "GA-SC" "TX" "CA" "MD" "ME" "MA" "LA" "MI" "MI" "TX" "WV" "WA" "OR" "MT" "NY" "AL" "ND" "VA" "IL" "IN" "PA" "ID" "MA-NH" "CO" "KY" "WA" "CT" "TX" "GA" "NY" "NC" "VT" "MD" "OH" "FL" "MO-IL" "IL" "NV" "WY" "IA" "PA" "IL" "WV" "SC" "NC-SC" "VA" "TN-GA" "WY" "IL-IN-WI" "CA" "OH-KY-IN" "TN-KY" "TN" "OH" "ID" "TX" "CO" "MO" "SC" "GA-AL" "IN" "OH" "TX" "OR" "FL" "MD-WV" "TX" "GA" "IL" "AL" "IA-IL" "OH" "AL" "IL" "FL" "CO" "IA" "MI" "AL" "DE" end
Comment