Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Dropping parts of strings (i.e. Baldwin County becomes Baldwin)
From
Andrew Maurer <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Dropping parts of strings (i.e. Baldwin County becomes Baldwin)
Date
Thu, 6 Mar 2014 17:13:00 +0000
Maybe not the most efficient way, but this works (replaces internal underscores with spaces):
local name __united_kingdom__+___county
di trim(subinstr(substr(`"`name'"',1,strpos(`"`name'"',"+")-1),"_"," ",.))
or for if your variable is named "oldname":
gen newname = trim(subinstr(substr(oldname,1,strpos(oldname,"+")-1),"_"," ",.))
(if you want internal underscores then gen newname2 = subinstr(newname," ","_",.)
Andrew Maurer
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Cody Cook
Sent: Thursday, March 06, 2014 11:02 AM
To: [email protected]
Subject: st: Dropping parts of strings (i.e. Baldwin County becomes Baldwin)
Hi Stata Helpers,
I have a ton of census data that I'm trying to merge with some other data. The other data only has county names, not FIPS.
For the census data, it is formatted as __name___ + ___ census type ___ where census type is either "County", "Borough", "Census Area" and maybe a few more. This is all in one string. I want to only keep the part that identifies the specific county.
Basically, is there a way to say "if county includes "XXXX" replace without "XXXX""
Best,
Cody
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/