Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: gen a newvar


From   Ron�n Conroy <[email protected]>
To   [email protected]
Subject   Re: st: gen a newvar
Date   Mon, 14 Mar 2005 17:18:14 +0000

Hans J. Baumgartner wrote:

Dear Statalist,

this may sound like a very silly question. But I seem to be unable to
solve it anyway.


My data looks like this:

id      x
1       5
1       5
1       10
1       10
1       21
1       21
1       21
2      ...

I want to generate a newvar with the maximum value of x , which is _N.
But if the difference between the largest and the second largest value
is <=7, newvar should take the value of the second largest value of x.

No single step solution, but

by id:gen max_x=x[_N]
by id:replace max_x=x[_N-1] if (x[_N] - x[_N-1]) <=7



--

Ronan M Conroy ([email protected]) Senior Lecturer in Biostatistics Royal College of Surgeons Dublin 2, Ireland +353 1 402 2431 (fax 2764) -------------------- Just say no to drug reps http://www.nofreelunch.org/

--------------------------------------------------------------------------------------------------------------------
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom
they are addressed.
If you have received this email in error please notify the
originator of the message. This footer also confirms that this
email message has been scanned for the presence of computer viruses.

Any views expressed in this message are those of the individual
sender, except where the sender specifies and with authority,
states them to be the views of The Royal College Of Surgeons in Ireland.

--------------------------------------------------------------------------------------------------------------------


*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index