Announcement

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

  • Data merge

    Dear All,

    I am doing a gravity model and I am having problems with merging two data sets, I want me data set to look like that (picture attached).

    Now I have a one world data set, with the GDP from 1990 till 2014 and another data set with the population for the same countries and time period.

    Could you please tell me how to merge them so that the data set will look like the picture I have attached?

    Attached Files

  • #2
    Please give a more precise description of the two datasets that you wish to merge. Even better, share excerpts from both datasets. You can use the dataex package for this, described in section 12 of the FAQ.

    Comment


    • #3
      I have attached two data sets, I want to merge them so that they will look like the previous photo I have attached, each country against each other (bilateral).

      Attached Files

      Comment


      • #4
        Originally posted by Mohamed Abdelrahman View Post
        I have attached two data sets, I want to merge them so that they will look like the previous photo I have attached, each country against each other (bilateral).
        The picture in post #1 is a screenshot of the Stata Data Editor but the variables don't match the two datasets attached to post #3.

        I assume you wish to carry out a 1:1 merge on the variables countrycode and time. This is documented in
        Code:
        help merge

        Comment


        • #5
          they are the same countries but before sort command, i just need to know if the merge command will list all countries against each other as in the screenshot

          Comment


          • #6
            Originally posted by Mohamed Abdelrahman View Post
            i just need to know if the merge command will list all countries against each other as in the screenshot
            Did you try what I proposed in post #4?

            Comment


            • #7
              yes I have applied the following:

              use "C:\Users\M.Abdelrahman\Desktop\merg 1.dta", clear
              sort countrycode time
              save "C:\Users\M.Abdelrahman\Desktop\merg 1.dta", replace
              clear
              use "C:\Users\M.Abdelrahman\Desktop\merge 2.dta", clear
              sort countrycode time
              save
              save "C:\Users\M.Abdelrahman\Desktop\merge 2.dta", replace
              clear
              cd "C:\Users\M.Abdelrahman\Desktop"
              merge 1:1 countrycode using merge2.dta

              but I got the following error
              . merge 1:1 countrycode using merge2.dta
              variable countrycode does not uniquely identify observations in the master data
              r(459);

              Comment


              • #8
                Indeed, countrycode alone is not sufficient for the merge. Please see what I wrote in post #4.

                Originally posted by Friedrich Huebler View Post
                I assume you wish to carry out a 1:1 merge on the variables countrycode and time.
                Code:
                merge 1:1 countrycode time using merge2.dta
                Last edited by Friedrich Huebler; 23 Oct 2015, 11:55.

                Comment


                • #9
                  I am sorry, I have read the help page for the merge command but I still cannot figure out what I did wrong, could you please clarify to me ?

                  Comment


                  • #10
                    Please see post #8.

                    Comment


                    • #11
                      thank you it worked

                      Comment

                      Working...
                      X