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)
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 ------------------
Dalila
0 Response to Using strpos to generate a new variable conditional on the last digit of another string
Post a Comment