[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: generate variable with the highest n-th non-missing value
Grote, Veit Dr.
> I have four variables (vacc~1 - vacc~4) giving the age of a
> vaccination. Three vaccinations are defined as "completed
> primary vaccination" (CPV). I like to find out the age of CPV.
> vac~1 vac~2 vac~3 vac~4 Freq
> 2 49 . . 3
> 2 . . . 2
> 3 23 . 2 2
> 4 5 . 22 1
> 4 13 . . 1
> 4 5 . 25 1
> With egen rfirst and rlast I can create a variable with the
> first and last non-missing value. In this case I like to
> create a variable with the 3rd non-missing value, like:
> "egen cpv=rnth(vacc*1 vacc*2 vacc*3 vacc*4), n(3)"
> Is there an easy solution like my egen vision?
> Acctually it is more complicated as the logical age order
> within each person from vacc~1-vac~4 is not preserved.
> Thus, I need the third highest value in varlist vacc~1-vac~4.
I take this to mean 3rd highest non-missing
value. What is to happen if that does not
exist, i.e. there are <= 2 non-missing
Any way, consider the results of
reshape long vacc, i(id)
gen ismiss = missing(vacc)
gsort id ismiss - vacc
by id : gen theoneIwant = vacc
* For searches and help try: