Announcement

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

  • merge files

    Hello everybody

    I need to merge 3 files a main one with two small others. I have a common variable as id ( the firmcode ). However I cannot find the way to match the observations from the 2 other files to the main one.

    If somebody can help, it would be very helpful.

    Thanks in advance

    TN

  • #2
    There are many ways in which one might be unable to match observations between files, and they require different solutions. I doubt anyone can help you with this unless you provide example data from all three data sets and a description of what you would like the final result to look like.

    To show the example data, please be sure to use the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      file 1 file 2 total file
      id var1 var2 id var3 group id var1 var2 var3 group
      1 65 895 1 745 1 1 65 895 745 1
      5 48 652 5 653 1 5 48 652 653 1
      8 35 423 15 258 1 15 22 487 258 1
      14 41 542 17 945 1 17 80 632 945 1
      15 22 487 20 241 1 20 49 159 241 1
      17 80 632 23 277 1
      20 49 159 29 123 1

      That is the simple merge I wanna made. The common id of file 1 and file 2 should be added in total file, including all the other vars.

      Thank you in advance
      T.N.

      Comment


      • #4
        Code:
        use `file1', clear
        merge 1:1 id using `file2', keep(match) nogenerate
        Note: I created the data sets as temporary files. Replace `file1' and `file2' in this code by the actual names of your data sets (with no `' around them).

        Comment


        • #5
          Thank you Prof. Schechter

          Comment

          Working...
          X