Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Calculating a maximum out of a subset in a sequence
From
<[email protected]>
To
[email protected]
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/