s-news
[Top] [All Lists]

Re: Coding Question

To: "Roberts, J. Kyle" <jkrobert@bcm.tmc.edu>
Subject: Re: Coding Question
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Tue, 24 Jan 2006 16:00:39 -0600
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <3FC0430478C30B4A9AF0AFF7863418F130EBA1@BCMEVS6.ad.bcm.edu>
Organization: PDF Solutions, Inc.
References: <3FC0430478C30B4A9AF0AFF7863418F130EBA1@BCMEVS6.ad.bcm.edu>
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)


Roberts, J. Kyle wrote:
I have a dataset in which I need to dummy code (sort of) two separate variables. Variable 1 I have 5 years of data on students in teachers classrooms. Each teacher entered the intervention at different times (years 1-6). I need to code a date variable for each student as zero for each student in the classroom before the intervention, and as a "1" when the intervention started. For example, in this case, the variable "new.var" would be created from "year" and "int.year".
teach  stud   year  int.year  new.var
1        1      1        3        0
1        2      1        3        0
1        3      2        3        0
1        4      2        3        0
1        5      3        3        1
1        6      3        3        1
1        7      4        3        1
1        8      4        3        1
Variable 2 This is like the above data, but I need the new.var.2 variable to begin counting up from the intervention year. For example:
teach  stud   year  int.year  new.var.2
1        1      1        3        0
1        2      1        3        0
1        3      2        3        0
1        4      2        3        0
1        5      3        3        1
1        6      3        3        1
1        7      4        3        2
1        8      4        3        2
Thanks,
Kyle
***************************************
J. Kyle Roberts, Ph.D.
Baylor College of Medicine
Center for Educational Outreach
One Baylor Plaza, MS:  BCM411
Houston, TX   77030-3411
713-798-6672 - 713-798-8201 Fax
jkrobert@bcm.edu
***************************************


How about (assuming `x' is your data.frame):

x$new.var <- ifelse(x$int.year >= x$year, 1, 0)
x$new.var.2 <- ifelse(x$int.year >= x$year, x$year - x$int.year + 1, 0)

HTH,

--sundar

<Prev in Thread] Current Thread [Next in Thread>
  • Coding Question, Roberts, J. Kyle
    • Re: Coding Question, Sundar Dorai-Raj <=