Identify the peers within a firm
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Long Hong
 el 29 de Feb. de 2020
  
    
    
    
    
    Comentada: Image Analyst
      
      
 el 18 de Mayo de 2020
            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
 where  and 1 indicates worker i's coworker's worker index in year t.
 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 comentarios
Respuesta aceptada
  Image Analyst
      
      
 el 29 de Feb. de 2020
        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 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Get Started with MATLAB en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




