Announcement

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

  • Append and merge issue

    How can I merge and append these data files (csv, dta and excel) where there are different number of observations in the different files?

    Thank you.
    Attached Files

  • #2
    People here are reluctant to open posted files. I'd recommend you ask a more detailed question.

    Comment


    • #3
      Originally posted by George Ford View Post
      People here are reluctant to open posted files. I'd recommend you ask a more detailed question.
      Thank you for the suggestion. This was my first question though.

      Comment


      • #4
        joinby/append/merge

        Comment


        • #5
          The best advice at this stage is to spend some time doing the work of reading in your datasets to Stata to understand their structure, and also the relevant documentation for importing and manipulating data. If you are completely new to Stata, then start with typing -help getting started- and reading through the first dozen or so chapters. If you have some familiarity with Stata already, then skip ahead to the documentation of importing data and the commands George suggested. Reading in data from Excel files can be achieved using -import excel- and from CSV files by using -import delimited- in turn.

          Appending concatenates data vertically, like stacking one dataset "on top of" another, while trying to align variables of the same name together. Merging (by -merge- or -joinby- or -frlink-) seeks to match data horizontally by groups formed by some kind of identifier (e.g., a personal id number).

          Once you've spent some time with this work, and you have reached some point where you need help, please post back. When you do, pay attention to the FAQ about how to ask questions here and how to post data examples using -dataex-.

          Comment


          • #6
            Originally posted by Leonardo Guizzetti View Post
            The best advice at this stage is to spend some time doing the work of reading in your datasets to Stata to understand their structure, and also the relevant documentation for importing and manipulating data. If you are completely new to Stata, then start with typing -help getting started- and reading through the first dozen or so chapters. If you have some familiarity with Stata already, then skip ahead to the documentation of importing data and the commands George suggested. Reading in data from Excel files can be achieved using -import excel- and from CSV files by using -import delimited- in turn.

            Appending concatenates data vertically, like stacking one dataset "on top of" another, while trying to align variables of the same name together. Merging (by -merge- or -joinby- or -frlink-) seeks to match data horizontally by groups formed by some kind of identifier (e.g., a personal id number).

            Once you've spent some time with this work, and you have reached some point where you need help, please post back. When you do, pay attention to the FAQ about how to ask questions here and how to post data examples using -dataex-.
            Thank you so much Leonardo!

            Comment


            • #7
              It looks like you have some course evaluations and want to attach some other info to that. This is a guess:

              Code:
              import excel TeachingRatings_Beauty.xls , firstrow clear
              save beauty, replace
              
              import delimited TeachingRatings_courseeval_200_463.csv , clear
              save eval2, replace
              
              import delimited TeachingRatings_courseeval_1_200.csv, clear
              append using eval2
              save eval, replace //could skip but if the latter fails then you can just come back to this. if the data is small, then skip.
              
              joinby teacherid using beauty, unmatched(master) _merge(_merge_beauty)
              tab _merge_beauty
              
              joinby teacherid using TeachingRatings_age, unmatched(master) _merge(_merge_age)
              tab _merge_age
              
              joinby teacherid using TeachingRatings_femaleindicator.dta, unmatched(master) _merge(_merge_female)
              tab _merge_female
              
              save eval_final, replace

              Comment

              Working...
              X