Hi,
I use the following code (found here) to remove certain legal forms from company names:
This code works just fine in most cases. If a company is registered under multiple legal forms though (e.g., "Test Company Corp Inc"), only the very last one will be removed, which will be "Inc" in the example. In order to control for these cases if have to remove the trailing spaces that where produced after the legal form is removed:
and then run the command again.
Is there a way to control for this so I don't have to run the commands over and over again until no further legal forms are removed? I tried to implement the #strrtrim command in the loop which however does not lead to the desired result.
Any help is much appreciated.
Thank you.
I use the following code (found here) to remove certain legal forms from company names:
Code:
clear
input str58 Acq_Name
"Atlas Pipeline Partners LP"
"Heartware International Inc"
"Thomson Reuters Corp"
"Patheon Inc"
"Lions Gate Entertainment Corp"
"Kodiak Oil & Gas Corp"
"SXC Health Solutions Corp"
"Catamaran Corp"
"Energy Fuels Inc"
"Domtar Corp"
end
local to_remove Inc Corp LP Ltd LLC Holdings Trust Partners & PLC Co Group
gen rname = reverse(Acq_Name)
foreach t of local to_remove {
local trev = reverse(`"`t'"')
replace Acq_Name = reverse(subinword(rname, `"`trev'"', "", 1)) ///
if strpos(rname, `"`trev'"') == 1
}
This code works just fine in most cases. If a company is registered under multiple legal forms though (e.g., "Test Company Corp Inc"), only the very last one will be removed, which will be "Inc" in the example. In order to control for these cases if have to remove the trailing spaces that where produced after the legal form is removed:
Code:
replace Acq_Name = strrtrim(Acq_Name)
Is there a way to control for this so I don't have to run the commands over and over again until no further legal forms are removed? I tried to implement the #strrtrim command in the loop which however does not lead to the desired result.
Any help is much appreciated.
Thank you.

Comment