Identify the peers within a firm

2 ビュー (過去 30 日間)
Long Hong
Long Hong 2020 年 2 月 29 日
コメント済み: Image Analyst 2020 年 5 月 18 日
Dear all:
I am working on a panel dataset, which contains worker ID, firm ID, and year. Each worker works for one firm only in each year - so it is a worker-year panel. I hope to create a matrix that shows whether worker j is worker i's coworker. Ideally, I hope to create a matrix as follows:
where and 1 indicates worker i's coworker's worker index in year t.
I am wondering if anyone knows how to have a quick algorithm instead looping over the worker's index (because there are thousands of workers in the data).
Thank you very much and I look forward to hearing from you!
Best,
Long
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 2 月 29 日
Can you elaborate more (Maths)?
Long Hong
Long Hong 2020 年 2 月 29 日
Hi Kalyan, thanks for asking! An easy example is as follows (two firms and one period).
IDw IDf
1 1
2 1
3 1
4 2
5 2
Then and . Hope it helps.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 2 月 29 日
You can simply use the firm vector and put it into pdist2(). Any distance that is zero means those two workers are in the same firm
firm2 = [firms(:), firms(:)];
distances = pdist2(firm2, firm2);
For example, if there is a zero at row 30 and column 142 of distances, it means that worker #30 and worker #142 work in the same firm.
  6 件のコメント
Long Hong
Long Hong 2020 年 5 月 17 日
Dear @Image Analyst,
I am writing to ask a very quick follow-up question on the use of pdist2,
Using my current (huge) data, pdist2 requires 0.7 million x 0.7 million matrix , and my computer cannot handle such a big matrix. Is there any way to solve this problem (say, adding a sparse matrix option since there are basically 0 and 1 in the matrix)?
Thank you, and I look forward to hearing from you!
Best,
Long
Image Analyst
Image Analyst 2020 年 5 月 18 日
No idea. Give it a try.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by