Dear Statalisters,

I'm struggling with Stata in handling a string problem. I have a dataset of industry sectors by SIC code. I have to distinguish between suppliers and competitors, therefore a first way to that is to chech whether firms are in the same 3digit SIC code. However I'm struggling in creating a variable that differs each time the last digitn in sic3dig changes.

i tried different combination of strpos like

Code:
bys  (bvd_sector): egen competitors = count(firmid) if strpos(sic_3dig, sic_lastdig)
I know that each code basically returns me no count because each sic_lastdig is in sic3dig. How can I do to have a variable that counts the number of firm within a 3 digit sector and changes everytime the last digit in the sic3dig changes.

Code:
---------------------- copy starting from the next line -----------------------

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str56 bvd_sector str3 sic3dig str1 sic_lastdig
"Banking" "960" "0"
"Banking" "961" "1"
"Banking" "962" "2"
"Banking" "963" "3"
"Banking" "962" "2"

end
------------------ copy up to and including the previous line ------------------
Hope I make myself clear and someone can help!!

Dalila