I am hoping to apply an efficient approach to searching and keeping observations. The following code finds key words in variables and keeps the observations with the key attributes. I am hoping to apply the same idea to a larger set of search terms and across a larger number of variables. Please let me know if you can see obvious improvements I could make or suggest alternative approaches. Thank you very much, Dan
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str63 Position strL(FirstName LastName) str36 Company "Managing Director" "Adam" "Angus" "ETF incorporated" "Chairman and CEO" "Bert" "Byron" "Invest Co.,LTD" "Senior Portfolio Manager / Head of Social Responsible Investing" "Chris" "Congo" "West ethical Private Bank" "Head of ESG Risk" "Dave" "Dove" "Responsible Investment and Insurance" "Marketing Consultant, Coach and CMO" "Edan" "Elad" "ESG advisors" end
Code:
gen terms_present1 = strpos(lower(Position), "esg" "environment" "environmental" "environmental, social and governance" "eco" "sustain" "sustainable" "sustainability" ) > 0 gen terms_present2 = strpos(lower(Position), "sri" "socially responsible investing" "responsible" "responsibly" "ethic" "ethics" "ethical") > 0 gen terms_present3 = strpos(lower(Company), "esg" "environment" "environmental" "environmental, social and governance" "eco" "sustain" "sustainable" "sustainability" ) > 0 gen terms_present4 = strpos(lower(Company), "sri" "socially responsible investing" "responsible" "responsibly" "ethic" "ethics" "ethical") > 0 count if terms_present1 > 0 count if terms_present2 > 0 count if terms_present3 > 0 count if terms_present4 > 0 keep if (terms_present1 + terms_present2 + terms_present3 + terms_present4) > 0
Comment