Announcement

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

  • Merging two data files when one of them seems to lack a unique identifier.

    So I have Stata data from a survey questionnaire split into multiple files to represent different sections of the survey (e.g. 'secc1' file which corresponds to the schooling / education section of the survey, 'seci' for immunization etc.). Issue is that while most sections have hhcode (household code) and idc (Person's identification code) and such things available to make merging easier, one section ('secl' which corresponds to "satsifaction with healthcare facilities" from the survey questionnaire) only has hhcode available and that doesn't seem to work as a unique identifier. I'm not sure how to go about merging this section with any of the others, or if it is even possible to do so in the first place. Someone mentioned using the duplicate command in some way to do something in this file that only has hhcode (household code) to make it fine for merging, but I'm not sure how that would work.

  • #2
    Assuming that your desired final dataset is at the individual level, you just need a 1:m (or m:1) merge between your household-level data and the individual-level data. If your individual-level data is in memory, then you can do something like

    Code:
    merge m:1 hhcode using <secl-file>
    (it is m:1 because multiple observations in the individual-level dataset are to be matched with 1 observation in the household-level dataset)
    Last edited by Hemanshu Kumar; 08 Feb 2025, 22:16.

    Comment


    • #3
      joinby also would work. I stopped using merge a long time ago given it had some issues (that may be been resolved, but I'm happy with joinby).

      Comment


      • #4
        I'm not sure I understand this statement:
        one section... only has hhcode available and that doesn't seem to work as a unique identifier
        Do you mean you have multiple non-duplicative observations with the same hhcode? If so, is it possible that the idc code was lost in an earlier round of data cleaning, and can be recovered?
        Devra Golbe
        Professor Emerita, Dept. of Economics
        Hunter College, CUNY

        Comment


        • #5
          Thank you, the m:1 merge worked.

          Comment

          Working...
          X