Dear Statalist masters,

I have a problem that I don't know how to code properly. I have investors (mgrno), dates, companies(permco) and shares (b) as variables of interest. Each permco can represent a company and its competitors, and for each company I want to find when they have the same investors of its competitors. When a company A has the same investor of competitor B I want to multiple their variable b and generate a new variable.



Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double mgrno long rdate double(permco b)
110 14244 14087 .0024507801650191976
110 14244 21127  .005213660739486311
110 14244 22807  .001346481548733134
110 14244 30905  .003654935372997047
110 14334 14087 .0024507801650191976
110 14334 21127 .0051131205019376265
110 14334 22807 .0013444534322613038
110 14334 30905  .003654935372997047
110 14425 14087 .0024507801650191976
110 14425 21127  .005080773814981205
110 14425 22807 .0012327773749093547
110 14425 30905  .003654935372997047
110 14517 22807 .0010884125920964502
110 14517 30905  .003654935372997047
110 15340  6708  .014552735298754532
110 15613  6708  .007002579274768624
110 15705  6708 .0069946199893915284
110 15795  6708  .006991441339089601
110 15886  6708   .00499637347767253
110 15978  6708 .0046660263862912605
110 16070  6708  .004160829389226955
110 16070  6708  .004160829389226955
110 16526 41578 .0013580634439971935
110 16526 44889 .0012966804979253112
110 17531 43350 .0018068479537446925
110 17622 43350 .0017774617845716318
110 17713 43350 .0017774617845716318
110 17805 43350 .0017774617845716318
110 17897 43350 .0017774617845716318
110 17987 43350 .0017627357659086903
110 18078 43350 .0017627357659086903
110 18170 43350 .0017627357659086903
110 18262 43350 .0017627357659086903
110 18352 43350 .0017627357659086903
110 18443 43350 .0017496282040066486
110 18535 43350 .0017496282040066486
110 18627 43350 .0017496282040066486
110 18717 43350 .0017496282040066486
110 18808 43350 .0017496282040066486
110 18900 43350 .0017496282040066486
end
format %d rdate