Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

RE: st: Analysis of event history data


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Analysis of event history data
Date   Wed, 21 Mar 2012 12:39:46 +0000

If all times are present and equally spaced, then you can do things like this (a "Yes, of course" trick I learned from Michael Blasnik): 

bysort id (time) : gen sumtodate = sum(employment) 

by id : gen sumlastyear = sumtodate - sumtodate[_n-52] 

For a more general procedure that copes with messier data, see 
 
SJ-7-3  pr0033  . . . . . . . . . . . . . .  Stata tip 51: Events in intervals
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q3/07   SJ 7(3):440--443                                 (no commands)
        tip for counting or summarizing irregularly spaced
        events in intervals

That is accessible at http://www.stata-journal.com/sjpdf.html?articlenum=pr0033

Nick 
[email protected] 

Kristian Thor Jakobsen

That's so true because I have one more.....

I now have my data sorted in the following way, where the variable status is a dummy indicating if a person has exited from a specific programme during a spell of unemployment. Now I need to calculate the average number of weeks that the person has been employed during e.g. the past two years before exiting this programme (for example, employment[_n-1] to employment[_n-104] if status[_n]==1), but I can't make STATA do the correct calculation (it is taking the mean total employment of each person).

Id      Status  Employment	Time
1       0       1		1
1       1       0		2
1       0       0		3
2       0       1		1
2       0       1		2	
2       0       0		3
3       0       0		1
3       0       1		2
3       1       1		3

Any idea of how to get around this?

Really appreciate the help.

Nick Cox

Never say "one final question"!

-help egen- shows that there are -egen- functions -anycount()-, -anymatch()-. -anyvalue()-. So

egen ones = anycount(y_*), values(1)
keep if ones

Even if those functions did not exist, you could do this

gen ones = 0

quietly foreach v of var y_* {
      replace ones = ones + (`v' == 1)
}

keep if ones

Nick


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index