Announcement

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

  • Creating Regions out of countries

    Generating Regions out of Countries.

    I have the following data set and I need to create regions from the countries which are listed. Regions should be as follows: -

    Region 1 = Canada and United States
    Region 2 = Japan, Australia and Hong Kong
    Region 3 = Everything else
    Data as follows

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str14 Country
    "United States" 
    "France"        
    "Poland"        
    "Australia"     
    "Germany"       
    "United States" 
    "United States" 
    "Germany"       
    "United States" 
    "Japan"         
    "Australia"     
    "Germany"       
    "United States" 
    "United Kingdom"
    "United States" 
    "Australia"     
    "Hong Kong"     
    "United Kingdom"
    "United Kingdom"
    "Canada"        
    "Germany"       
    "Japan"         
    "Germany"       
    "United Kingdom"
    "Germany"       
    "United States" 
    "United Kingdom"
    "Germany"       
    "Canada"        
    "Japan"         
    "United Kingdom"
    "United States" 
    "Australia"     
    "Italy"         
    "Hong Kong"     
    "United Kingdom"
    "United States" 
    "United States" 
    "Hong Kong"     
    "Germany"       
    "Hong Kong"     
    "United States" 
    "Sweden"        
    "United States" 
    "Netherlands"   
    "United States" 
    "Switzerland"   
    "Belgium"       
    "United States" 
    "United States" 
    "Germany"       
    "United Kingdom"
    "Poland"        
    "France"        
    "Germany"       
    "Sweden"        
    "Sweden"        
    "Australia"     
    "Germany"       
    "United States" 
    "Sweden"        
    "Switzerland"   
    "United Kingdom"
    "United States" 
    "United States" 
    "France"        
    "Japan"         
    "United Kingdom"
    "France"        
    "United States" 
    "United States" 
    "Germany"       
    "Norway"        
    "Germany"       
    "Japan"         
    "Japan"         
    "Hong Kong"     
    "Belgium"       
    "United States" 
    "Germany"       
    "Netherlands"   
    "Germany"       
    "United States" 
    "Sweden"        
    "Canada"        
    "Germany"       
    "United Kingdom"
    "United States" 
    "Canada"        
    "Sweden"        
    "France"        
    "Germany"       
    "Canada"        
    "Germany"       
    "Netherlands"   
    "Germany"       
    "Australia"     
    "Germany"       
    "United States" 
    "Japan"         
    end
    Thanks for your help

    Giles

  • #2
    Starting with your sample data,
    Code:
    . generate region = 3
    
    . replace region = 1 if inlist(Country,"United States","Canada")
    (29 real changes made)
    
    . replace region = 2 if inlist(Country,"Japan","Australia","Hong Kong")
    (18 real changes made)
    
    . tab region
    
         region |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |         29       29.00       29.00
              2 |         18       18.00       47.00
              3 |         53       53.00      100.00
    ------------+-----------------------------------
          Total |        100      100.00
    This is fairly fundamental Stata code, unless I have misunderstood your intent. It leads me to the following advice which may prove helpful.

    When I began using Stata in a serious way, I started as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. All of these manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through Stata's Help menu. The objective in doing this was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and manual.

    Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

    Comment


    • #3
      You are right William this is fundamental and should be easy I have read the user guide cover to cover. I will start to read the more detailed manuals that sit below this as well when I have some more time.

      I'm just battling deadlines at the minute.

      Comment

      Working...
      X