Statalist


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

st: RE: identifying spells in panel data


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: identifying spells in panel data
Date   Thu, 24 Sep 2009 16:01:03 +0100

On behalf of all Coxes everywhere, especially numero uno Sir David, I'd
like to request the spelling Cox regression. 

Note that -spell- (SSC) is superseded by -tsspell- (SSC), but neither is
not applicable to wide format data anyway. 

In this case, you can just concatenate your data into one string and
look for spells using -strpos()-. 

egen wall = concat(w1-w48) 

gen workspell = strpos(wall, "0000") 

This will return the start week of the first such spell if there is one
and 0 otherwise. 

Hence 

gen byte success = workspell > 0 

In general, however, you'd be better off after a -reshape- to long. 

See also 

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying
spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N.
J. Cox
        Q2/07   SJ 7(2):249--265                                 (no
commands)
        shows how to handle spells with complete control over
        spell specification


Nick 
[email protected] 

Morten Vejs Willert

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?

*
*   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