Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: Finding patterns of consecutive number

From   Marshall Garland <>
Subject   st: Finding patterns of consecutive number
Date   Wed, 25 Apr 2012 17:47:11 -0500


I have panel student testing data spanning six years. Each year, I
have a unique student and student test level and outcome. Testing
levels across years are not necessarily consecutive, nor are years.
For each student, in each year, I'd like to create a variable that
captures the longitudinal test progression for each student, in each
year. However, for each year, I'd like the maximum consecutive test
progression, without disruptions. This maximum test progression should
only be calculated for consecutive years, too.

I've posted my data at the end of this message, which will help
describe my objective. For student A, in 2008/09, her test progression
is 6543, since she had 4 consecutive years of test data. This is
perfect. Student B, however, in 2008/09, has a test progression of
7643. However, I only want to record, for student B, the maximum
consecutive test progression, which is 76 and ignore the 43. The 43
progression will be captured in the corresponding year (2006/07).

I can't figure out a way to adjust for this discontinuity. I've tried
a number of things, including this. But, this still captures repeated
test levels across years (student C below, in 2008/09).

Thanks for help in advance.



bys research_id: gen test_t=d.test_level_2
bys research_id: egen max_test_t=max(test_t)

///group creation for consecutive runs
forvalues i=0/6 {
	gen group_`i'=.
	bys research_i (sch_yr): replace group_`i'=test_level_2[_n-`i'] if
max_test_t==1 & test_t==1
	tostring group_`i', replace
	replace group_`i'="" if group_`i'=="."

egen group_ty_cons=concat(group_0- group_6)
tab group_ty_cons

Here's my data:
student	year	test_level	progression
A	2005/06	3	
A	2006/07	4	43
A	2007/08	5	543
A	2008/09	6	6543
B	2005/06	3	
B	2006/07	4	43
B	2007/08	6	643
B	2008/09	7	7643
C	2005/06	6	
C	2006/07	7	76
C	2007/08	8	876
C	2008/09	8	8876
*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index