JodeCharger100
JodeCharger100

Reputation: 1059

How to append two datasets when there are non-unique columns?

I have two datasets, A and B.

Dataset A has 2000 variables, and Dataset B has 2500. Both A and B have common variables.

How do I append the two datasets?

Below you can find a toy example:

Dataset A:

Name    Age    Sex    Occupation
a        10     M      Engineer

Dataset B:

Name    Age    Sex     Children    Income
b        33     F         Y          50

I need to append such that the final dataset looks as follows:

Name    Age    Sex    Occupation   Children    Income
a        10     M      Engineer       .          . 
b        33     F          .          Y          50

Missing values get generated for lack of observations.

Upvotes: 0

Views: 93

Answers (1)

user8682794
user8682794

Reputation:

The following works for me:

clear

input str1 Name Age str1 Sex str10 Occupation
a 10 M Engineer
end

save one, replace

clear

input str1 Name Age str1 Sex str1 Children Income
b 33 F Y 50
end

save two, replace

use one, clear
append using two

list, abbreviate(10)

     +---------------------------------------------------+
     | Name   Age   Sex   Occupation   Children   Income |
     |---------------------------------------------------|
  1. |    a    10     M     Engineer                   . |
  2. |    b    33     F                       Y       50 |
     +---------------------------------------------------+

Note that Stata generates a . only for missing values in numeric variables. For strings, a space is generated instead.

Upvotes: 1

Related Questions