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 at the end of May, and its replacement, is already up and running.

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

Re: st: Start/End dates to ongoing count indicators

From   Jeremy Wells <>
Subject   Re: st: Start/End dates to ongoing count indicators
Date   Tue, 23 Apr 2013 12:40:35 -0500

I think that got it, but I needed to use -collapse- instead because I also had
some interval-level variables that needed to be summed.


Jeremy Wells
Ph.D. Student
LSU Dept. of Poli. Sci.
324 Stubbs Hall
Baton Rouge, LA 70803

I assume numeric variables with formats showing Stata weekly dates.

First you need an observation identifier

gen long obsid = _n

and then a duration count

gen duration = EndDt - StDt  + 1

and then you want one observation per week

expand duration

Tidy up the dates

bysort obsid : gen Week = StDt[1] + _n - 1


contract Week Class

and finally it's a -reshape-.


On 23 April 2013 17:04, Jeremy Wells <
> wrote:

> I have a dataset where observations are unique projects. Each project
> has a start week and end week variable, as well as a classification variable,
> so the data structure looks like this:
> StDt                    EndDt           Class
> 2002wk1         2002 wk3                1
> 2002wk4         2002wk6         1
> 2002wk1         2002wk5         2
> 2002wk4         2002wk5         2
> What I would like to have is time series data with each observation a week
> and variables for each class with a count of the number of ongoing projects
> in each class in each week, so the data would look like this:
> Week            Class1          Class2
> 2002 wk1                1                       1
> 2002wk2         1                       1
> 2002wk3         1                       1
> 2002wk4         1                       2
> 2002wk5         1                       2
> 2002wk6         1                       0
> The first though is -tab class, gen(class)-, but that will give me a 1 for the
> start week only, but I want the count to continue to the end week.

*   For searches and help try:

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