Announcement

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

  • how can i combine two datasets like this?

    Hi, I want to combine two datasets. Here is an example of what i have:

    Dataset A:
    id Country Gender Income Education
    1 E M 100 9
    2 S F 100 10
    3 V M 50 7
    4 S M 90 8
    Dataset B:
    Contry Index
    E 5
    S 10
    V 8
    And i want two combine data set A with data set B with a new variable of the index by contry. Like this:
    id Country Gender Income Education Index
    1 E M 100 9 5
    2 S F 100 10 10
    3 V M 50 7 8
    4 S M 90 8 10
    Thank you

  • #2
    You will want to use the merge command. First you need to load your "master" dataset. I will assume this is dataset A in your example. Then you will need to merge this dataset with dataset B like the following:

    Code:
    merge 1:1 id using "datasetB.dta"
    where id refers to the country id you will use to match. It has to be in both datasets. DatasetB.dta refers to the name of your second dataset. You will need to put the entire directory of where the dataset can be found--not only the name of the file. However, if you set your directory and have all files in the same location, you can just type the name of the second dataset as above.

    Comment

    Working...
    X