Hi there

I am looking to create two variables based on the below example data. I would like to create two variables showing:
  • the total number of previous investments the investor has made in that specific industry or sector
  • the percentage of all previous investments made by the investor which were in that specific industry or sector
The important point is that the variables are purely for each specific individual investor (and not for all investors together) and that they should evolve over time, within each investor.

I attach below a data example (the data is sorted by investor and date):


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(date year) str45 targetfirm str10 investor str38 industry str22 sector
14250 1999 "Travelex Group Limited"                        "Investor A" "Consumer Finance"                       "Financials"            
14266 1999 "Storyboards Harpers Ltd"                       "Investor A" "Advertising"                            "Communication Services"
14297 1999 "Shorterm Limited"                              "Investor A" "Human Resource and Employment Services" "Industrials"           
14388 1999 "Neville Johnson Ltd"                           "Investor A" "Home Furnishings"                       "Consumer Discretionary"
14416 1999 "Open Business Solutions Limited"               "Investor A" "Application Software"                   "Information Technology"
14423 1999 "Opt-Tel Holdings Limited"                      "Investor A" "Office Services and Supplies"           "Industrials"           
14424 1999 "The Adscene Group, Ltd."                       "Investor A" "Publishing"                             "Communication Services"
14549 1999 "Tamdown Group Ltd"                             "Investor A" "Construction and Engineering"           "Industrials"           
14622 2000 "APM TERMINALS MANAGEMENT -BARCELONA- SL"       "Investor A" "Marine Ports and Services"              "Industrials"           
14628 2000 "MI Services Group Ltd."                        "Investor A" "IT Consulting and Other Services"       "sector"                
14690 2000 "Freshtime UK Ltd"                              "Investor A" "Packaged Foods and Meats"               "Consumer Staples"      
14700 2000 "Balfour 2000"                                  "Investor A" "Food Retail"                            "Consumer Staples"      
14739 2000 "Logicom Integrated Logistics Company Ltd"      "Investor A" "Distributors"                           "Consumer Discretionary"
14741 2000 "Knürr GmbH"                                   "Investor A" "Electronic Manufacturing Services"      "Information Technology"
14761 2000 "British International Helicopters Limited"     "Investor A" "Airlines"                               "Industrials"           
14762 2000 "Ingenco Limited"                               "Investor A" "Construction and Engineering"           "Industrials"           
14791 2000 "Open Solutions, S.L."                          "Investor A" "IT Consulting and Other Services"       "Information Technology"
14819 2000 "Autocue Group Ltd"                             "Investor A" "Communications Equipment"               "Information Technology"
14861 2000 "Bongard, S.A.S"                                "Investor A" "Industrial Machinery"                   "Industrials"           
14868 2000 "Jaycare Limited"                               "Investor A" "Metal and Glass Containers"             "Materials"             
14910 2000 "Careshare"                                     "Investor A" "Education Services"                     "Consumer Discretionary"
14929 2000 "Peter Black Holdings Ltd"                      "Investor A" "Footwear"                               "Information Technology"
14934 2000 "Selkirk Europe Ltd."                           "Investor A" "Industrial Machinery"                   "Information Technology"
14944 2000 "Grupo Combursa, S.L."                          "Investor A" "Building Products"                      "Industrials"           
14965 2000 "Fairview New Homes Limited"                    "Investor A" "Homebuilding"                           "Consumer Discretionary"
15979 2003 "Rollon S.p.A."                                 "Investor B" "Industrial Machinery"                   "Industrials"           
17317 2007 "DOUGLAS ITALIA S.p.A. and DOUGLAS CHERO S.p.A" "Investor B" "Oil and Gas Refining and Marketing"     "Energy"                
18452 2010 "NUTKAO S.r.l."                                 "Investor B" "Packaged Foods and Meats"               "Consumer Staples"      
18799 2011 "MACRON S.P.A."                                 "Investor B" "Apparel, Accessories and Luxury Goods"  "Consumer Discretionary"
19099 2012 "Tucano Urbano Srl"                             "Investor B" "Distributors"                           "Consumer Discretionary"
19540 2013 "CELLI S.p.A."                                  "Investor B" "Industrial Machinery"                   "Industrials"           
20102 2015 "Manifattura Riese S.p.a."                      "Investor B" "Apparel, Accessories and Luxury Goods"  "Consumer Discretionary"
13969 1998 "Home Innovations, Inc."                        "Investor C" "Home Furnishings"                       "Consumer Discretionary"
14067 1998 "Value Partners Limited"                        "Investor C" "Asset Management and Custody Banks"     "Financials"            
14175 1998 "Brooks Sports, Inc."                           "Investor C" "Footwear"                               "Consumer Discretionary"
14275 1999 "Strategic Outsourcing, Inc."                   "Investor C" "Human Resource and Employment Services" "Industrials"           
14587 1999 "Consumer Health Interactive Inc."              "Investor C" "Application Software"                   "Information Technology"
15006 2001 "RBC Bearings Incorporated (NasdaqGS:ROLL)"     "Investor C" "Industrial Machinery"                   "Industrials"           
15853 2003 "Amisys Synertech Inc."                         "Investor C" "Health Care Technology"                 "Health Care"           
15853 2003 "Synertech Health Systems Solutions"            "Investor C" "Research and Consulting Services"       "Industrials"           
15874 2003 "Pure Fishing, Inc."                            "Investor C" "Leisure Products"                       "Consumer Discretionary"
16321 2004 "Eastern Mountain Sports, Inc."                 "Investor C" "Apparel Retail"                         "Consumer Discretionary"
16462 2005 "Stauber Performance Ingredients, Inc."         "Investor C" "Food Distributors"                      "Consumer Staples"      
17086 2006 "Ignite Restaurant Group, Inc."                 "Investor C" "Restaurants"                            "Consumer Discretionary"
10330 1988 "Huntsman Polymers Corporation"                 "Investor D" "Diversified Chemicals"                  "Materials"             
13076 1995 "Motor Wheel Corporation"                       "Investor D" "Auto Parts and Equipment"               "Consumer Discretionary"
13472 1996 "Video River Networks, Inc. (OTCPK:NIHK)"       "Investor D" "Communications Equipment"               "Information Technology"
13916 1998 "Builders FirstSource, Inc. (NasdaqGS:BLDR)"    "Investor D" "Building Products"                      "Industrials"           
15853 2003 "Mosaic US Holdings Inc."                       "Investor D" "Advertising"                            "Communication Services"
16099 2004 "PGT Innovations, Inc. (NYSE:PGTI)"             "Investor D" "Building Products"                      "Industrials"           
16369 2004 "C.H.I. Overhead Doors, Inc."                   "Investor D" "Building Products"                      "Industrials"           
16379 2004 "Education Affiliates Inc."                     "Investor D" "Education Services"                     "Consumer Discretionary"
16397 2004 "Medical Card System, Inc."                     "Investor D" "Life and Health Insurance"              "Financials"            
16642 2005 "The J.G. Wentworth Company"                    "Investor D" "Consumer Finance"                       "Financials"            
16959 2006 "Populus Financial Group, Inc."                 "Investor D" "Consumer Finance"                       "Financials"            
20004 2014 "HAHN Automation GmbH"                          "Investor E" "Industrial Machinery"                   "Industrials"           
20100 2015 "Heidelberg Instruments Mikrotechnik GmbH"      "Investor E" "Semiconductor Equipment"                "Information Technology"
20366 2015 "Pell Frischmann Group Ltd."                    "Investor E" "Construction and Engineering"           "Industrials"           
20501 2016 "Dorsch Holding GmbH"                           "Investor E" "Construction and Engineering"           "Industrials"           
21097 2017 "McBains Limited"                               "Investor E" "Construction and Engineering"           "Industrials"           
21319 2018 "40-30 SAS"                                     "Investor E" "Diversified Support Services"           "Industrials"           
17364 2007 "Clearstone Ltd."                               "Investor F" "Human Resource and Employment Services" "Industrials"           
17737 2008 "SWCORP4 Limited"                               "Investor F" "Publishing"                             "Communication Services"
17992 2009 "Morses Club PLC (AIM:MCL)"                     "Investor F" "Consumer Finance"                       "Financials"            
18618 2010 "S.Robinson & Sons(Engineers) Ltd."             "Investor F" "Steel"                                  "Materials"             
18627 2010 "Malton Foods Limited"                          "Investor F" "Packaged Foods and Meats"               "Consumer Staples"      
18833 2011 "Benchmark Scaffolding Ltd."                    "Investor F" "Construction and Engineering"           "Industrials"           
19323 2012 "The Harley Medical Group"                      "Investor F" "Health Care Facilities"                 "Health Care"           
19347 2012 "City Motor Holdings Ltd."                      "Investor F" "Automotive Retail"                      "Consumer Discretionary"
19626 2013 "Shropshire Leisure Group Ltd"                  "Investor F" "Hotels, Resorts and Cruise Lines"       "Consumer Discretionary"
19663 2013 "Four Seasons Maintenance Ltd."                 "Investor F" "Construction and Engineering"           "Industrials"           
19702 2013 "Redhills Limited"                              "Investor F" "Environmental and Facilities Services"  "Industrials"           
19792 2014 "Shopacheck Financial Services Ltd"             "Investor F" "Consumer Finance"                       "Financials"            
19802 2014 "Giffen Group Limited"                          "Investor F" "Construction and Engineering"           "Industrials"           
end
format %tddd-Mon-YY date


If anything is unclear, please do not hesitate to ask.

Many thanks
Paul