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: Choosing the Minimum Value and Recording Variable Name


From   Erika Kociolek <ekociole@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Choosing the Minimum Value and Recording Variable Name
Date   Wed, 3 Apr 2013 06:45:23 -0700

I am working with a dataset that looks like this:

id  drug1  drug2  drug3  drug4  drug5  drug6
1   10     20     30      .      .      .
2   40     30      .     50      .      .

I'd like write code that finds the minimum value of drug* and for each
observation, puts the name of the variable with this minimum value in
a new variable (let's call it minimum_var), i.e.:

id  drug1  drug2  drug3  drug4  drug5  drug6 minimum_var
1   10     20     30      .      .      .    drug1
2   40     30      .     50      .      .    drug2

I would prefer to do this without reshaping the data, and know that I
will need to account for ties.

Thank you in advance for your assistance!

Erika
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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