Announcement

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

  • Recode/replace values of a string variable with numeric codes

    I have a dataset that has a geographic identifier (districts) that uses the actual string name of the district e.g Surrey, Essex. I would like to recode each district with a particular numerical code that I have in an Excel file. There are several hundred districts so typing "replace district=1 if district=Surrey" will take a very long time. Is there a shortcut at all?

  • #2
    How is the spreadsheet organized? If it has one column for the numeric codes and one column for the names, you can first convert the file into a Stata data file (with the location names as a string variable that has the same name as your existing Stata data). Then use -merge 1:1- to match on the location names.

    Comment


    • #3
      Now I see in your other post that you mentioned the the spelling is inconsistent. Well, then it all depends on how inconsistent the spelling is. Perhaps sorting both data files, and manually checking the consistency between names in the alphabetical order would be easy. Alternatively, someone recently recommended the user-written package -reclink-. It is designed to match datasets that have imperfectly corresponding information.

      Comment

      Working...
      X