Hello
 
I have a longitudinal dataframe organized in the long format and would like to make 
comparison between successive rows if certain conditions apply. Specifically, I have 
four variables of interest: grade, score, year, and schid, associated with each school 
with 3 measurements per school per grade, therefore the rows are temporally ordered 
and each school occupies multiple rows. For example, a school may have grades 4,5,6 
and three observations per grade at years 2001-2003 and therefore occupies 9 rows.
 
So, my goal is to make a comparison between score 1 and 2 (same column, next row) if 
the score is from the same school, same grade, but one year later and create a new 
binary variable if score 1 < score 2.
 
Something like, ifelse(data[x,4] with data[x,4], if schid=schid and grade = grade, and 
year = year + 1, 1, 0)
 
So, I will end up with a new variable in the data frame where 1 indicates that 
subsequent score is larger than the score for the same grade in the same school in 
year t-1.
 
I'm a little confused how conditional selection would work in such a scenario. 
 
Many thanks,
 
Harold
 
 
 

        [[alternative HTML version deleted]]

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to