Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remove Parentheses

    I have a panel dataset consisting of 17 Spanish regions. I want to clean up the region names so that I may eventually make unique panel IDs from the region name variable. Consider the full list below.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str28 regionname
    "Spain (Espana)"              
    "Andalucia"                  
    "Aragon"                      
    "Principado De Asturias"      
    "Baleares (Islas)"            
    "Canarias"                    
    "Cantabria"                  
    "Castilla Y Leon"            
    "Castilla-La Mancha"          
    "Cataluna"                    
    "Comunidad Valenciana"        
    "Extremadura"                
    "Galicia"                    
    "Madrid (Comunidad De)"      
    "Murcia (Region de)"          
    "Navarra (Comunidad Foral De)"
    "Basque Country (Pais Vasco)"
    "Rioja (La)"                  
    end
    All I'd like is to eliminate all of the text between (and including) the parentheses. So, if we have "Madrid (Comunidad De)", I would like for it to just be "Madrid".


    My original idea was to simply use the split command to break everything off from the left parentheses, but I wondered if there was a more elegant way (i.e., regex) to accomplish this. How might I do this? Cassie Wright

    EDIT:

    When asking questions, you wanna give as broad a characterization of your problem as possible. So, use this dataex
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input strL Q10_a
    "MEng Chemical Engineering, MA Natural Sciences"                                                                                                                      
    "MEng Chemical Engineering  PhD Chemical Engineering and Analytical Science"                                                                                          
    "BSc Mathematics"                                                                                                                                                     
    "BSc Maths"                                                                                                                                                           
    "BSc electrical engineering"                                                                                                                                          
    "BSc Mathematics"                                                                                                                                                     
    "MEng Civil engineering with German"                                                                                                                                  
    "BA in Mathematics and Philosophy"                                                                                                                                    
    "BSc Maths, MSc Maths"                                                                                                                                                
    "BEng Electronic and Electrical Engineering"                                                                                                                          
    "BA, MMath, PhD in pure maths"                                                                                                                                        
    "BEng Mechanical Engineering"                                                                                                                                         
    "MEng Chemical Engineering"                                                                                                                                           
    "Chemical engineering"                                                                                                                                                
    "Mechanical Engineering"                                                                                                                                              
    "MEng Mechanical Engineering"                                                                                                                                         
    "BSc Mathematics"                                                                                                                                                     
    "MEng Computer Systems Engineering"                                                                                                                                   
    "MEng in Medical Engineering, currently undertaking PhD in Engineering"                                                                                               
    "BSc Mathematics and Computer Science"                                                                                                                                
    "BEng Chemical Engineering  MSc Biotechnolgy  MPhil Chemical Engineering"                                                                                             
    "BEng Mechanical Engineering"                                                                                                                                         
    "BEng Mechanical Engineering"                                                                                                                                         
    "BSc electronics/software engineering"                                                                                                                                
    "MEng Civil Engineering"                                                                                                                                              
    "BSc Electrical and Electronic Engineering"                                                                                                                           
    "MEng Civil Engineering"                                                                                                                                              
    "BEng (hons) Engineering Geology and Geotechnics"                                                                                                                     
    "BSc HONS Electrical and Electronic Engineering"                                                                                                                      
    "MEng Aerospace Engineering"                                                                                                                                          
    "MEng Engineering Science"                                                                                                                                            
    "Aeronautics and astronautics engineering"                                                                                                                            
    "BSc Civil Engineering"                                                                                                                                               
    "BSc Mechanical Engineering  PGCE Physics"                                                                                                                            
    "BEng Engineering,   Currently studying MSC Engineering"                                                                                                              
    "B.A. Engineering  MEng Engineering."                                                                                                                                 
    "BEng Manufacturing Engineering"                                                                                                                                      
    "NVQ aircraft maintenance  BTEC aerospace engineering"                                                                                                                
    "BSc Mechanical Engineering"                                                                                                                                          
    "MEng civil engineering graduated 2000 and now studying an msc in railway systems engineering and integration hoping to graduate at the end of the year"              
    "BEng The Special Engineering Programme"                                                                                                                              
    "Bsc Applied Maths and Computer Studies"                                                                                                                              
    "BEng Aerospace Engineering and  MSc Engineering and Management"                                                                                                      
    "BEng (Hons) Automotive Engineering"                                                                                                                                  
    "Beng civil engineering"                                                                                                                                              
    "BEng Mechanical Engineering"                                                                                                                                         
    "BSc Motorsport Engineering"                                                                                                                                          
    "BEng Mechanical engineering"                                                                                                                                         
    "HND software engineering"                                                                                                                                            
    "MEng Mechanical Engineering"                                                                                                                                         
    "Engineering MEng"                                                                                                                                                    
    "Engineering & Materials Sciences B.Sc., Metallurgy & Science of Materials D.Phil"                                                                                    
    "BSc Engineering"                                                                                                                                                     
    "MMath Mathematics, PhD Mathematics"                                                                                                                                  
    "BSc Engineering"                                                                                                                                                     
    "MEng Chemical Engineering"                                                                                                                                           
    "BEng Hons (1st) Mechanical Engineering"                                                                                                                              
    "MEng Civil Engineering"                                                                                                                                              
    "BA engineering"                                                                                                                                                      
    "BSc Maths & Stats  MSc Medical Stats  PhD Medical  Stats"                                                                                                            
    "MEng Chemical Engineering"                                                                                                                                           
    "MEng Civil Engineering"                                                                                                                                              
    "BSc Engineering"                                                                                                                                                     
    "Engineering"                                                                                                                                                         
    "Nuclear Engineering"                                                                                                                                                 
    "BEng Chemical Process Engineering with Biotechnology  PhD in Physical Chemistry"                                                                                     
    "MEng Civil Engineering with European Studies"                                                                                                                        
    "Currently working towards BEng Electrical & Electronic Engineering"                                                                                                  
    "BSc Mathematics  MSc Military Vehicle Technology"                                                                                                                    
    "BEng Production Engineering"                                                                                                                                         
    "BSc in River and Coastal Engineering"                                                                                                                                
    "MEng Architectural Engineering"                                                                                                                                      
    "mechanical engineering MEng"                                                                                                                                         
    "BEng Automotive Engineering"                                                                                                                                         
    "Mechanical Engineering (MEng)"                                                                                                                                       
    "MEng Aviation Engineering"                                                                                                                                           
    "MEng Civil Engineering"                                                                                                                                              
    "MEng Civil Engineering"                                                                                                                                              
    "BSc Engineering"                                                                                                                                                     
    "Mathematics"                                                                                                                                                         
    "BEng Mechanical Engineering"                                                                                                                                         
    "MEng Master of Engineering with Honors Design Engineering with an Industrial Placement Year"                                                                         
    "BSc Maths & Computing"                                                                                                                                               
    "MMath Mathematics"                                                                                                                                                   
    "MEng Product Design Engineering"                                                                                                                                     
    "Civil Engineering"                                                                                                                                                   
    "Electronic Engineering"                                                                                                                                              
    "Manufacturing Engineering Degree"                                                                                                                                    
    "Chemical Engineering"                                                                                                                                                
    "MEng Civil Engineering"                                                                                                                                              
    "BEng Mechanical Engineering"                                                                                                                                         
    "MEng Chemical Engineering"                                                                                                                                           
    "MEng Electrical and Electronic Engineering"                                                                                                                          
    "MEng Aerospace Engineering"                                                                                                                                          
    "Degree Apprenticeship which included NVQ level 2 and 4 in Advance engineering and Manufacturing and Beng in Materials Engineering and Mechanical Design in areospace"
    "MEng Civil Engineering"                                                                                                                                              
    "MEng Chemical Engineering"                                                                                                                                           
    "MEng Electronic Engineering"                                                                                                                                         
    "MEng Mechanical Engineering"                                                                                                                                         
    "MSc Engineering"                                                                                                                                                     
    end
    cls
    
    replace Q10_a = "math" if Q10_a =="BSc Maths"
    
    g studies = 1 if strpos(Q10_a, "Engineering") | strpos(Q10_a, "engineering")
    replace studies = 2 if strpos(Q10_a, "math")
    
    br if studies ==.
    This example creates the problem- how to generalize making a level 2 when some values have "Math" and others just have "math"
    Last edited by Jared Greathouse; 18 Jul 2022, 09:57.
Working...
X