Announcement

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

  • replace if the individual belongs to a given group

    Hi.
    I have a dataset including around 200 countries (and several observations for each country).
    I would like to generate the following dummies: low_income; lower_middle_income; upper_middle_income; high_income.
    The list of countries belonging to each group is obtained from the site of the WorldBank (http://data.worldbank.org/about/coun...lending-groups).
    Since for each group the list of countries included is quite long, I was looking for an alternative to the command: replace low_income=1 if country=="Afghanistan"|county=="Gambia"....
    Do you have any idea?
    I was thinking to create several globals (like, for example: global low_income "Afghanistan Gambia, The Myanmar Bangladesh Guinea Nepal Benin"), but then I don't know how to say: replace low_income=1 if country belongs to global low_income.
    Thank you for your help!

  • #2
    There are a couple of ways of doing this.

    1. If you save the country and income group in a dataset, you could merge that with your dataset.

    2. If you want to use macros, you would do something like this:

    Code:
    local countries `""American Samoa" "Malaysia" "Samoa" "Cambodia" "Marshall Islands" "Solomon Islands""'
    
    
    gen inc_lev = .
    foreach country of local countries   {
       replace inc_lev = 1 if country==`"`country'"'
    }

    Comment


    • #3
      At one level, you could use the inlist() function. See e.g. http://www.stata-journal.com/sjpdf.h...iclenum=dm0026

      At another level, consider http://www.stata.com/support/faqs/da...teristics.html

      Comment


      • #4
        Going to the link in your post, that page contains a link "Click to download the country classification table." If you do that, you will get an Excel file that lists, among other things, the country names in column D and the income group in column H. You can -import excel- that file to convert it to a Stata data set, and then -merge- it with your own data set. Then you can generate the dummies you want by -encode-ing the income group variable and using factor variables in your analysis, or by -tab income_group, gen(dummies)-.

        Comment


        • #5
          Thank you!

          Comment

          Working...
          X