Hi Everyone,

Bellow in the -dataex- example, I have a zipcode, date (month_year) and name of an installer. I need to generate:
1- a new var that is equal to the number of repetitions the installer name is repeated in month_year and in zipcode (for example, how many times "Tesla" is repeated in "92105" in 2015m5).
2- another new var, that is a ratio equal to [number of repetitions the installer name is repeated in month_year and in zipcode / the total number of installers in the same zipcode and same month_year].

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long zipcode float month_year str54 installer
92101 638 "milenderwhiteconstructioncompany"  
92082 674 "fidelityhomeenergy"                
91910 564 "alternativeenergytechnologies"     
91910 690 "empoweredenergysolutions"          
92129 691 "altaxenergy"                       
92021 665 "westcoastsolar"                    
92109 682 "atechconstruction"                 
92131 642 "aecom"                             
92105 687 "tesla"                             
92021 686 "naturalenergy"                     
91911 689 "omneco"                            
92064 694 "bakerelectric"                     
92122 686 "sunpower"                          
92101 614 "borregosolar"                      
92028 668 "tesla"                             
92673 541 "newvisiontechonologies"            
92064 547 "westernsolar"                      
92121 673 "sullivansolarpower"                
92114 652 "evolutionenergy"                   
92120 677 "bappower"                          
92066 694 "rosspowersolutions"                
92126 671 "asesolarsolutions"                 
91910 596 "southcoastenergy"                  
92026 671 "westernsolar"                      
91950 685 "goldenwestenergy"                  
92127 683 "sunpower"                          
92064 583 "recsolar"                          
92081 658 "maedlsolarelectric"                
91950 620 "evolutionenergy"                   
92064 677 "independentenergysolutions"        
92672 585 "teamsolar"                         
92121 521 "kerrenterprises"                   
92029 691 "sunpower"                          
92123 670 "bakerelectric"                     
92110 675 "hmtelectricsolar"                  
91950 644 "sunpower"                          
92028 653 "sunfusionsolar"                    
92037 687 "solartech"                         
92130 688 "californiapremiersolarconstruction"
92102 677 "sullivansolarpower"                
91950 674 "gcelectricco"                      
92075 693 "bakerelectric"                     
92003 638 "borregosolar"                      
91950 620 "evolutionenergy"                   
92020 694 "sunpower"                          
91914 684 "empoweredenergysolutions"          
91941 621 "hawkinsconstruction"               
92029 677 "bakerelectric"                     
92082 686 "pureenergysolar"                   
92065 665 "solareenergy"                      
92173 693 "smartsolarsolutions"               
92121 633 "sullivansolarpower"                
92020 656 "solartech"                         
92101 602 "affirmedhousinggroup"              
92024 685 "bmcsolar"                          
92026 692 "t&msolar"                          
92064 665 "solareenergy"                      
91942 671 "precisionelectric"                 
92024 679 "sunpower"                          
92106 620 "spgsolar"                          
92694 644 "californiapremiersolarconstruction"
92026 693 "sunpower"                          
92027 677 "selfinstaller"                     
92021 677 "sjelectricco"                      
92108 663 "homeenergysystems"                 
92028 669 "selfinstaller"                     
92021 685 "pacificbeachtower"                 
92103 546 "borregosolar"                      
92127 668 "borregosolar"                      
92082 671 "pureenergysolar"                   
92026 645 "westernsolar"                      
92127 662 "hercasolar"                        
92121 622 "californiasolarinnovations"        
92025 656 "homeenergysystems"                 
92065 672 "saselectrical"                     
91917 674 "bakerelectric"                     
92113 613 "evolutionenergy"                   
92129 667 "empoweredenergysolutions"          
92056 673 "independentenergysolutions"        
92019 694 "sunpower"                          
91950 621 "evolutionenergy"                   
92064 671 "selfinstaller"                     
92069 691 "californiapremiersolarconstruction"
92075 686 "bakerelectric"                     
92122 639 "aecom"                             
92103 674 "starpower"                         
92029 690 "sunpower"                          
92113 616 "heliopower"                        
92173 659 "evolutionenergy"                   
92130 655 "borregosolar"                      
91914 662 "socoreinstallationservices"        
92081 671 "bakerelectric"                     
92081 689 "heliopower"                        
92065 686 "homeenergysystems"                 
92121 675 "cosmicsolar"                       
91942 671 "precisionelectric"                 
92111 681 "greenenergyepc"                    
92028 674 "precisionelectric"                 
91942 671 "precisionelectric"                 
92064 643 "evolutionenergy"                   
end
format %tm month_year

Thank you
Ali