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, statalist.org is already up and running.


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

st: Calculating a maximum out of a subset in a sequence


From   <benignor@javeriana.edu.co>
To   statalist@hsphsun2.harvard.edu
Subject   st: Calculating a maximum out of a subset in a sequence
Date   Mon, 3 Oct 2011 19:03:38 -0400

I am the original poster of this question.

I found a very inelegant solution:

	. gen index = 1 if C4NAIVC ~=.|CD4MEMC ~=.
	(252 missing values generated)

	. sort patid WEEK1

	. by patid: egen obsnum = seq()

	. by patid: replace index = . if (index[_n-1] ==. & obsnum >1)
	(191 real changes made, 191 to missing)

	. by patid: egen LatestNaive = max(WEEK1) if index ==1
	(443 missing values generated)

	. by patid: replace LatestNaive=LatestNaive[_n-1] if LatestNaive ==.
	(395 real changes made)

	. drop index

Surely there is a less cumbersome way to achieve the same result?

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index