Hello,
I am using Stata 15.1, working with data that looks like this:
I would like to only keep observations that contain county names - Richland, Sumter, Florence, Horry, Charleston, Marlboro, Spartanburg, and Newberry. I believe this could be accomplished using the strpos command, but I am struggling to run the correct loop within that command.
Once that is accomplished, I would like to only keep the same strings within variable values. For example, "Spartanburg GS" would become "Spartanburg" and "Sitting with Milling Sumter GS 26, 27, 28" would become "Sumter."
Thank you.
I am using Stata 15.1, working with data that looks like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str22 ALFORD113 str17 BARBER110 str41(BAXLEY121 BEATTY103) str20 BREEDEN106 "16th Cir. CPNJ/PCR" "Richland GS" "Sitting with Milling Sumter GS 26, 27, 28" "Florence CP" "Horry CP" "16th Cir. CPNJ/PCR" "Richland GS" "Sitting with Milling Sumter GS 26, 27, 28" "Florence CP" "Horry CP" "16th Cir. CPNJ/PCR" "Richland GS" "Sitting with Milling Sumter GS 26, 27, 28" "Florence CP" "Horry CP" "York GS" "Richland CP" "Charleston CP" "7th Cir. CPNJ" "Marlboro GS" "York GS" "Richland CP" "Charleston CP" "7th Cir. CPNJ" "Marlboro GS" "-x-" "Richland CP" "Charleston CP" "Spartanburg GS" "Horry CP" "-x-" "Richland CP" "Charleston CP" "Spartanburg GS" "Horry CP" "-x-" "Richland CP" "Charleston CP" "Spartanburg GS" "Horry CP" "-x-" "Richland CP" "Charleston CP" "Spartanburg GS" "Horry CP" "-x-" "Richland CP" "Charleston CP" "Spartanburg GS" "Horry CP" "York GS" "" "Newberry GS" "" "" "York GS" "" "Newberry GS" "" "" "York GS" "" "Newberry GS" "" "" end
Once that is accomplished, I would like to only keep the same strings within variable values. For example, "Spartanburg GS" would become "Spartanburg" and "Sitting with Milling Sumter GS 26, 27, 28" would become "Sumter."
Thank you.
Comment