I have such a sample dataset and want to count the year span sorted by specific variables.
See this sample data. -fyear- is the fiscal year, -conm- is the supplier name, -cnms- is the customer name, -salecs- is the sales between a supplier and a customer. Now I want to count the year span that one supplier has transaction record with a customer. For example, the supplier "REGENERON PHARMACEUTICALS" has a transaction with his customer "AMGEN INC" first time in 1993 and last time in 1997. Thus the year span should be five. However, not all suppliers have single customers. See the supplier "MEDAREX INC". He has a transaction with "PFIZER INC" in 2004 and another transaction with "BMC SOFTWARE INC" in 2005. Thus his year spans with respective customers are only one.
Hope I have clarified the logic clearly. Thank you guys in advance.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double fyear str58(conm cnms) double salecs 1993 "REGENERON PHARMACEUTICALS" "AMGEN INC" 6.1 1994 "REGENERON PHARMACEUTICALS" "AMGEN INC" 9.9 1995 "REGENERON PHARMACEUTICALS" "AMGEN INC" 7.8 1996 "REGENERON PHARMACEUTICALS" "AMGEN INC" 5.8 1997 "REGENERON PHARMACEUTICALS" "AMGEN INC" 1.5 1995 "PMC-SIERRA INC" "APPLE INC" 45.294 1996 "PMC-SIERRA INC" "APPLE INC" 18.936 1997 "PMC-SIERRA INC" "APPLE INC" 5.087 1997 "ICOS CORP" "ABBOTT LABORATORIES" 2 2004 "MEDAREX INC" "PFIZER INC" 2.495 2005 "MEDAREX INC" "BMC SOFTWARE INC" 17.495 2005 "SEPRACOR INC" "AMERISOURCEBERGEN CORP" 197.023 1995 "READ-RITE CORP" "QUANTUM CORP" 290.882 1996 "READ-RITE CORP" "QUANTUM CORP" 287.424 1997 "READ-RITE CORP" "QUANTUM CORP" 209.169 1998 "READ-RITE CORP" "QUANTUM CORP" 24.259 1994 "AUTOCAM CORP" "HUTCHINSON TECHNOLOGY INC" 7.078 1997 "IMCLONE SYSTEMS INC" "MERCK & CO" 3.667 2002 "IMCLONE SYSTEMS INC" "ABBOTT LABORATORIES" 1.352 2003 "IMCLONE SYSTEMS INC" "ABBOTT LABORATORIES" .554 1992 "SPECTRANETICS CORP" "MEDTRONIC PLC" 1.696 end
0 Response to Issue about Counting Time Spans Sorted by Specific Variables
Post a Comment