0

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.

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.