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: reshape without index

From   Maarten Buis <>
Subject   Re: st: reshape without index
Date   Wed, 15 Jun 2011 09:02:55 +0200

On Tue, Jun 14, 2011 at 9:47 PM, Caleb Southworth wrote:
> I would like to set up these data for a an event history analysis and
> use the -stset- command. Id is the organization id, begin is the begin
> date, end is the end date. Here's a snippet:
> I want to end up with a dataset where year (decimal year) is the unit
> of analysis and where a variable death=1 where year==end else death=0.
> Do I need to reshape these data? Or is there a way to stset the data
> for a stcox model in the current format?

Creating a dataset where you have multiple observations per
organization makes sense if you want to merge in variables that
changed over time. In that case you can create such a dataset using
the example below. If you do not have such time varying covariates,
you can just -stset- the dataset as is.

*-------------- begin example ----------------------
clear all
input ///
str5 id begin      end
6119A   1947.716   1958.862
3158A   1948.269   1960.003
3216A   1948.504   1950.537
3192A   1948.558    1962.77
3119A   1949.483       1985
3189A   1950.333   1959.403
9841A   1952.088       1985
9973A   1953.908   1954.176
3181A   1957.574    1958.74
3011A   1958.772   1971.583
9951A   1958.789       1985

gen dyear = floor(end) + 1 - floor(begin)
expand dyear
bys id: gen year = floor(begin) + _n - 1
gen byte died = year == floor(end)

sort id year
list in 1/40 , sepby(id)
*------------------ 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–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index