Event History Data Recoding

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Event History Data Recoding

Thomas Jensen-6
Dear R list,

I have an event history data set that is structured like this:

Legislative act     Discussion     Agreement     Time     Event
Act1                2006-05-30     2006-06-19     20        1
Act2                2004-03-01     2004-06-14     105       1
.                  
.
.

I have information on the meetings in the legislature between adoption
periods in a separate variable (the start and stop dates are included):

Act1 meeting:2006-05-30, 2006-06-19.
Act2 meeting: 2004-03-22, 2004-04-26, 2004-06-14.

I want to code this as a discrete event data set, so it should look like
this:

Legislative act     Event     Meeting     Time Count
Act1                  0       2006-05-30      1
Act1                  1       2006-06-07      2
Act2                  0       2004-03-22      1
Act2                  0       2004-04-26      2
Act2                  1       2004-06-14      3

Can anyone tell me if it is possible to do this recoding in R, or do I
have to do it by hand?

Best, Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Event History Data Recoding

Joshua Wiley-2
If you are talking about changing from a "wide" format to "long" take a look at

?reshape


---
Josh

On Fri, Apr 23, 2010 at 7:09 AM, Thomas Jensen
<[hidden email]> wrote:

> Dear R list,
>
> I have an event history data set that is structured like this:
>
> Legislative act     Discussion     Agreement     Time     Event
> Act1                2006-05-30     2006-06-19     20        1
> Act2                2004-03-01     2004-06-14     105       1
> .
> .
> .
>
> I have information on the meetings in the legislature between adoption
> periods in a separate variable (the start and stop dates are included):
>
> Act1 meeting:2006-05-30, 2006-06-19.
> Act2 meeting: 2004-03-22, 2004-04-26, 2004-06-14.
>
> I want to code this as a discrete event data set, so it should look like
> this:
>
> Legislative act     Event     Meeting     Time Count
> Act1                  0       2006-05-30      1
> Act1                  1       2006-06-07      2
> Act2                  0       2004-03-22      1
> Act2                  0       2004-04-26      2
> Act2                  1       2004-06-14      3
>
> Can anyone tell me if it is possible to do this recoding in R, or do I
> have to do it by hand?
>
> Best, Thomas
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Event History Data Recoding

Thomas Jensen-6
Thanks Josh,

But I am not sure if the reshape function can create new rows based on
the meeting variable. For the second act there are three meetings, i.e.
one meeting between discussion and agreement, and this should be entered
as a separate row.

Best, Thomas

On Fri, 2010-04-23 at 07:45 -0700, Joshua Wiley wrote:

> If you are talking about changing from a "wide" format to "long" take a look at
>
> ?reshape
>
>
> ---
> Josh
>
> On Fri, Apr 23, 2010 at 7:09 AM, Thomas Jensen
> <[hidden email]> wrote:
> > Dear R list,
> >
> > I have an event history data set that is structured like this:
> >
> > Legislative act     Discussion     Agreement     Time     Event
> > Act1                2006-05-30     2006-06-19     20        1
> > Act2                2004-03-01     2004-06-14     105       1
> > .
> > .
> > .
> >
> > I have information on the meetings in the legislature between adoption
> > periods in a separate variable (the start and stop dates are included):
> >
> > Act1 meeting:2006-05-30, 2006-06-19.
> > Act2 meeting: 2004-03-22, 2004-04-26, 2004-06-14.
> >
> > I want to code this as a discrete event data set, so it should look like
> > this:
> >
> > Legislative act     Event     Meeting     Time Count
> > Act1                  0       2006-05-30      1
> > Act1                  1       2006-06-07      2
> > Act2                  0       2004-03-22      1
> > Act2                  0       2004-04-26      2
> > Act2                  1       2004-06-14      3
> >
> > Can anyone tell me if it is possible to do this recoding in R, or do I
> > have to do it by hand?
> >
> > Best, Thomas
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Event History Data Recoding

Joshua Wiley-2
I'm sorry, I do not think I understand exactly what your data is and
what your end goal is.  Are all your meeting dates together (i.e.,
they need to be split apart into separate cells)?


On Fri, Apr 23, 2010 at 8:18 AM, Thomas Jensen
<[hidden email]> wrote:

> Thanks Josh,
>
> But I am not sure if the reshape function can create new rows based on
> the meeting variable. For the second act there are three meetings, i.e.
> one meeting between discussion and agreement, and this should be entered
> as a separate row.
>
> Best, Thomas
>
> On Fri, 2010-04-23 at 07:45 -0700, Joshua Wiley wrote:
>> If you are talking about changing from a "wide" format to "long" take a look at
>>
>> ?reshape
>>
>>
>> ---
>> Josh
>>
>> On Fri, Apr 23, 2010 at 7:09 AM, Thomas Jensen
>> <[hidden email]> wrote:
>> > Dear R list,
>> >
>> > I have an event history data set that is structured like this:
>> >
>> > Legislative act     Discussion     Agreement     Time     Event
>> > Act1                2006-05-30     2006-06-19     20        1
>> > Act2                2004-03-01     2004-06-14     105       1
>> > .
>> > .
>> > .
>> >
>> > I have information on the meetings in the legislature between adoption
>> > periods in a separate variable (the start and stop dates are included):
>> >
>> > Act1 meeting:2006-05-30, 2006-06-19.
>> > Act2 meeting: 2004-03-22, 2004-04-26, 2004-06-14.
>> >
>> > I want to code this as a discrete event data set, so it should look like
>> > this:
>> >
>> > Legislative act     Event     Meeting     Time Count
>> > Act1                  0       2006-05-30      1
>> > Act1                  1       2006-06-07      2
>> > Act2                  0       2004-03-22      1
>> > Act2                  0       2004-04-26      2
>> > Act2                  1       2004-06-14      3
>> >
>> > Can anyone tell me if it is possible to do this recoding in R, or do I
>> > have to do it by hand?
>> >
>> > Best, Thomas
>> >
>> > ______________________________________________
>> > [hidden email] mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>
>>
>
>



--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Event History Data Recoding

Don MacQueen
In reply to this post by Thomas Jensen-6
The reshape() function would be used to reorganize your event history
data set so that the Discussion and Agreement dates are one above the
other in the same column, presumably with another variable to flag
which is which (although you don't seem to need that).

Then, separately, you read your "information" data into R, reorganize
it into the same structure as the reshaped event history, and then
append it to the reshaped event history (using the rbind() function),
and finally, sort.

That's my best guess given what you've shown. But there are puzzles,
i.e., dates in the inputs that are not in the output, and dates in
the output that are not in the input. Event=0 shows up in the output
but not in the input. The "information" dataset doesn't have event
numbers.

Reading the "information" file into R and reorganizing into columns
with the correct structure for appending looks tricky.

-Don


At 5:18 PM +0200 4/23/10, Thomas Jensen wrote:

>Thanks Josh,
>
>But I am not sure if the reshape function can create new rows based on
>the meeting variable. For the second act there are three meetings, i.e.
>one meeting between discussion and agreement, and this should be entered
>as a separate row.
>
>Best, Thomas
>
>On Fri, 2010-04-23 at 07:45 -0700, Joshua Wiley wrote:
>>  If you are talking about changing from a "wide" format to "long"
>>take a look at
>>
>>  ?reshape
>>
>>
>>  ---
>>  Josh
>>
>>  On Fri, Apr 23, 2010 at 7:09 AM, Thomas Jensen
>>  <[hidden email]> wrote:
>>  > Dear R list,
>>  >
>>  > I have an event history data set that is structured like this:
>>  >
>>  > Legislative act     Discussion     Agreement     Time     Event
>>  > Act1                2006-05-30     2006-06-19     20        1
>>  > Act2                2004-03-01     2004-06-14     105       1
>>  > .
>>  > .
>>  > .
>>  >
>>  > I have information on the meetings in the legislature between adoption
>>  > periods in a separate variable (the start and stop dates are included):
>>  >
>>  > Act1 meeting:2006-05-30, 2006-06-19.
>>  > Act2 meeting: 2004-03-22, 2004-04-26, 2004-06-14.
>>  >
>>  > I want to code this as a discrete event data set, so it should look like
>>  > this:
>>  >
>>  > Legislative act     Event     Meeting     Time Count
>>  > Act1                  0       2006-05-30      1
>>  > Act1                  1       2006-06-07      2
>>  > Act2                  0       2004-03-22      1
>>  > Act2                  0       2004-04-26      2
>>  > Act2                  1       2004-06-14      3
>>  >
>>  > Can anyone tell me if it is possible to do this recoding in R, or do I
>>  > have to do it by hand?
>>  >
>>  > Best, Thomas
>>  >
>>  > ______________________________________________
>>  > [hidden email] mailing list
>>  > https://*stat.ethz.ch/mailman/listinfo/r-help
>>  > PLEASE do read the posting guide
>>http://*www.*R-project.org/posting-guide.html
>>  > and provide commented, minimal, self-contained, reproducible code.
>>  >
>>
>>
>>
>
>______________________________________________
>[hidden email] mailing list
>https://*stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Event History Data Recoding

Corey Sparks
In reply to this post by Thomas Jensen-6
did you look at the survSplit() function in the survival library?  you may have to recode your date variable to a zero point, i.e. Jan 1 1900 = 0, and measure your time like that.  The survSplit function will split your survival duration into specified cut points.  I hope this helps
Corey
Corey Sparks, PhD
Associate Professor
Department of Demography
University of Texas at San Antonio
501 West César E. Chávez  Blvd
Monterey Building 2.270C
San Antonio, TX 78207
210-458-3166
corey.sparks 'at' utsa.edu
coreysparks.weebly.com