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: expanding a large data set and merging with another data set

From   Maarten Buis <>
Subject   Re: st: expanding a large data set and merging with another data set
Date   Wed, 24 Apr 2013 10:33:26 +0200

On Wed, Apr 24, 2013 at 10:01 AM, David Jose wrote:
> I have two data sets, one which contains daily pollution data, and
> another which contains a data set on individuals. The individual-level
> data has information on the date of birth and date of death, and I
> would like to merge these two data sets, so that the resulting data
> set is an individual-level data set, where for each individual I have
> pollution exposure for each day of life.

So the challenge is to expand a dataset with one row per person with
only date of birth and date of death such that it has one row for each
person's day in which (s)he was alive. This is what -stsplit- is for:

*------------------ begin example ------------------
clear all
input personid    dob         dod
      1           14610       14976
      2           16557       18114
format dob dod %td

gen byte died = 1
stset dod, origin(dob) id(personid) failure(died)

stsplit time , every(1)
gen date = time + dob
format date %td

list personid dob dod date in 1/10
*------------------- end example -------------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

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