Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: AW: combining datasets

From   Maarten buis <>
Subject   Re: st: AW: combining datasets
Date   Thu, 19 Aug 2010 08:34:53 +0000 (GMT)

--- On Wed, 18/8/10, martine etienne wrote:
> firstly, person 1 in dataset A is NOT same person as person
> 1 in dataset B, measurements are also taken at different times
> secondly, I would like the final dataset to look like Final 1

Here is an example of how to do that:

*------------ begin example ------------
// create the two datasets
tempfile a b

drop _all
input id x
1  3
2  4
save `a'

drop _all
input id x
1  5
2  6
save `b'

// create a new variable in each dataset
// that identifies the source of those
// observations
use `a'
gen source = "a"

save `a', replace

use `b'
gen source = "b"
save `b', replace

// use -append- to stack the datasets
append using `a'

// create a extra id variable, which contains
// an unique integer for each source-id combination
// and attaches the values of the source and id
// variables to the value label
egen long new_id = group(source id), label

// for display purposes I put the thre id variables
// to the left of the dataset
order id source new_id

// display the result
*--------------- end example ----------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index