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.

# Re: st: Choosing the Minimum Value and Recording Variable Name

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: Choosing the Minimum Value and Recording Variable Name Date Wed, 3 Apr 2013 16:00:25 +0100

SJ-9-1  pr0046  . . . . . . . . . . . . . . . . . . .  Speaking Stata: Rowwise
(help rowsort, rowranks if installed) . . . . . . . . . . .  N. J. Cox
Q1/09   SJ 9(1):137--157
shows how to exploit functions, egen functions, and Mata
for working rowwise; rowsort and rowranks are introduced

for a review of some technique in this territory.

On 3 April 2013 15:07, Ryan Kessler <ryan.kessler.stata@gmail.com> wrote:
> How about something like this?
>
> input id drug1 drug2 drug3
> 1 0 10 100
> 2 100 10 0
> 3 10 0 100
> end
>
> egen min=rowmin(drug*)
> gen min_var = ""
> foreach v of varlist drug* {
> replace min_var = "`v'" if `v' == min
> }
>
> Best,
>
> Ryan Kessler
>
>
> On Wed, Apr 3, 2013 at 9:45 AM, Erika Kociolek <ekociole@gmail.com> wrote:
>> 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.
>>
>>
>> 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/
> *
> *   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/

--
Nick
njcoxstata@gmail.com
*
*   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/