Hi,

I have unbalanced panel data set of around 2000 companies over 40 years. I have to calculate average distance of a company from companies in same industry year wise. I've latitude and longitude data of companies, what I want is to generate new variables based on latitude and longitude of competitor firms of same industry so that distance from each competitor company and average distance can be calculated. I'm unable to figure out how to do this. Anyone can help please. Data is given, where permno is company ID and ffind49 is industry dummy.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(permno fiscalyear) byte ffind49 float(latitude_f longitude_f)
10006 1975 25  38.78394  -90.48123
10006 1976 25  38.78394  -90.48123
10006 1977 25  38.78394  -90.48123
10006 1978 25  38.78394  -90.48123
10006 1979 25  38.78394  -90.48123
10006 1980 25  38.78394  -90.48123
10006 1981 25  38.78394  -90.48123
10006 1982 25  38.78394  -90.48123
10006 1983 25  38.78394  -90.48123
10007 1989 36 33.448376 -112.07404
10010 1986 12  40.17455  -74.92267
10010 1987 12  40.17455  -74.92267
10010 1988 12  40.17455  -74.92267
10010 1989 12  40.17455  -74.92267
10010 1990 12  40.17455  -74.92267
10010 1991 12  40.17455  -74.92267
10010 1992 12  40.17455  -74.92267
10010 1993 12  40.17455  -74.92267
10010 1994 12  40.17455  -74.92267
10012 1987 37 33.709187 -117.95367
10012 1988 37 33.709187 -117.95367
10012 1989 37 33.709187 -117.95367
10012 1990 37 33.709187 -117.95367
10012 1991 37 33.709187 -117.95367
10012 1992 37 33.709187 -117.95367
10012 1993 37 33.709187 -117.95367
10012 1994 37 33.709187 -117.95367
10012 1995 37 33.709187 -117.95367
10012 1996 37 33.709187 -117.95367
10012 1997 37 33.709187 -117.95367
10012 1998 37 33.709187 -117.95367
10012 1999 37 33.709187 -117.95367
10012 2000 37 33.709187 -117.95367
10012 2001 37 33.709187 -117.95367
10012 2002 37 33.709187 -117.95367
10012 2003 37 33.709187 -117.95367
10015 1983 44  36.15398  -95.99277
10015 1985 44  36.15398  -95.99277
10016 1986 12   41.4645  -81.50874
10016 1987 12   41.4645  -81.50874
10016 1988 12   41.4645  -81.50874
10016 1989 12   41.4645  -81.50874
10016 1990 12   41.4645  -81.50874
10016 1991 12   41.4645  -81.50874
10016 1992 12   41.4645  -81.50874
10016 1993 12   41.4645  -81.50874
10016 1994 12   41.4645  -81.50874
10016 1995 12   41.4645  -81.50874
10016 1996 12   41.4645  -81.50874
10016 1997 12   41.4645  -81.50874
10016 1998 12   41.4645  -81.50874
10016 1999 12   41.4645  -81.50874
10016 2000 12   41.4645  -81.50874
10017 1986 35  40.30428  -74.10042
10017 1987 35  40.30428  -74.10042
10019 1986 38 37.692238  -97.33755
10019 1987 38 37.692238  -97.33755
10019 1988 38 37.692238  -97.33755
10019 1989 38 37.692238  -97.33755
10019 1990 38 37.692238  -97.33755
10019 1991 38 37.692238  -97.33755
10019 1992 38 37.692238  -97.33755
10019 1993 38 37.692238  -97.33755
10019 1994 38 37.692238  -97.33755
10019 1995 38 37.692238  -97.33755
10019 1996 38 37.692238  -97.33755
10019 1997 38 37.692238  -97.33755
10019 1998 38 37.692238  -97.33755
10019 1999 38 37.692238  -97.33755
10019 2000 38 37.692238  -97.33755
10025 1986 15  41.04676  -74.02292
10025 1987 15  41.04676  -74.02292
10025 1988 15  41.04676  -74.02292
10025 1989 15  41.04676  -74.02292
10025 1990 15  41.04676  -74.02292
10025 1991 15  41.04676  -74.02292
10025 1992 15  41.04676  -74.02292
10025 1993 15  41.04676  -74.02292
10025 1994 15  41.04676  -74.02292
10025 1995 15  41.04676  -74.02292
10025 1996 15  41.04676  -74.02292
10025 1997 15  41.04676  -74.02292
10025 1998 15  41.04676  -74.02292
10025 1999 15  41.04676  -74.02292
10025 2000 15  41.04676  -74.02292
10025 2001 15  41.04676  -74.02292
10025 2002 15  41.04676  -74.02292
10025 2003 15  41.04676  -74.02292
10025 2004 15  41.04676  -74.02292
10025 2005 15  41.04676  -74.02292
10025 2006 15  41.04676  -74.02292
10025 2007 15  41.04676  -74.02292
10025 2008 15  41.04676  -74.02292
10025 2009 15  41.04676  -74.02292
10025 2010 15  41.04676  -74.02292
10025 2011 15  41.04676  -74.02292
10025 2012 15  41.04676  -74.02292
10025 2013 15  41.04676  -74.02292
10025 2014 15  41.04676  -74.02292
10025 2015 15  41.04676  -74.02292
end
------------------ copy up to and including the previous line ------------------

Listed 100 out of 16120 observations