Statalist


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

st: AW: identifying spells in panel data


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: identifying spells in panel data
Date   Thu, 24 Sep 2009 14:46:29 +0200

<> 

Check this very carefully:


*************
clear*
set obs 102
set seed 12345

gen id=_n 

forv i=1/48{
	gen byte w`i'=runiform()<0.5
}

reshape long w, i(id) j(week)
l in 1/40, noobs 

tsset id week

bysort id (week): gen byte success= /* 
*/ (L3.w==0)*(L2.w==0)*(L.w==0)*(w==0)

bysort id (week): gen byte successtime= /* 
*/ cond((_n<4), 0, success*(L3.week))

l in 1/40, noobs
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Morten Vejs
Willert
Gesendet: Donnerstag, 24. September 2009 14:12
An: [email protected]
Betreff: st: identifying spells in panel data

In relation to performing a cox regression, I am looking for a way to
identify spells in a dataset containing longitudinal panel data of 48
week-by-week registrations on absenteeism from work.

The dataset is in wide format. For each participant(=id) there are 48
variables (one per week) containing either the value 0 (=working) or
the value 1 (=absent from work). The week-by-week variables are named
consecutively w1, w2, w3, ... w48, as illustrated below:

id     w1     w2     w3     w4     w5     w6 ..... w48
1       1       1       1       0       0       0          0
2       1       0       0       0       0       0          0
3       1       1       1       1       1       0          0
4       0       0       0       0       0       0          0
...
102   1       1       1       1       0       0          0


I am interested in determining when a participant has had a spell of
four consecutive weeks working - so in my dataset I want to identify
spells of 4 consecutive 0's, when combing through the variable w1 to
w48 - and I want to generate two new variables: 'success' describing
if the participant has had such a spell (values 0 or1), and
'successtime' denoting the first week of the identified spells (values
1 to 45).

I have tried to use the command -spell- to achieve this, but with no
success. Does anyone have a solution to this problem?


Best regards
Morten Vejs Willert
*
*   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/


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index