Announcement

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

  • STATA Commands for a simple vlookup like algorithm

    I have about 100 files with the same 24 variables and 400,000 obs each. They are missing the county code associated with each obs. I have another file that can match one of the variable's values to a county code. How do I code a way to take a value in the first file, find it and match another variable, same observation in the second file, and retain that value in the first file. My instinct is that there is a way to use "generate" and index/match to create a new variable in file 1 with the county code. Help!

  • #2
    This is a job for merge. Let's call the file that matches one of the variables in the 100 other files to a county code county_crosswalk.dta. Then
    Code:
    use one_of_the_100_data_files, clear
    merge m:1 variable_that_can_match using county_crosswalk, keep(master match) nogenerate
    save, replace
    Substitute actual filename and variable name for the italicized parts.

    And since you have 100 such files you will probably want to wrap that all in a nice loop over the files.
    Last edited by Clyde Schechter; 16 Jun 2023, 15:51.

    Comment

    Working...
    X