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 at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: egen rowmin but not value but variable name


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: egen rowmin but not value but variable name
Date   Mon, 13 Aug 2012 12:19:26 +0100

There is an extended review of working rowwise at

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

which is accessible to all as a .pdf under the Stata Journal's 3 year window.

Nick

On Mon, Aug 13, 2012 at 12:16 PM, Trelle Sven <strelle@ctu.unibe.ch> wrote:
> Thanks Nick, it works fine for me!
> Sven
>
> p.s. Thread closed from my side.
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
> Sent: Montag, 13. August 2012 13:03
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: egen rowmin but not value but variable name
>
> Ties can be tracked like this
>
> sysuse auto, clear
>
> gen which_min = "price"
> gen min = price
>
> qui foreach v of var mpg-gear_ratio {
>       replace which_min = "`v'" if `v' < min
>       replace which_min = which_min + " `v'" if `v' == min
>       replace min = `v' if `v' < min
> }
>
> subject to a constraint of 244 characters on the variable holding
> variable names.
>
> On Mon, Aug 13, 2012 at 11:57 AM, Phil Clayton
> <philclayton@internode.on.net> wrote:
>> You may also need to consider what to do about ties.
>>
>> Phil
>>
>> On 13/08/2012, at 8:53 PM, Nick Cox wrote:
>>
>>> Dopey example. Which is minimum of price-gear_ratio in auto data?
>>>
>>> sysuse auto, clear
>>>
>>> gen which_min = "price"
>>> gen min = price
>>>
>>> qui foreach v of var mpg-gear_ratio {
>>>      replace which_min = "`v'" if `v' < min
>>>       replace min = `v' if `v' < min
>>> }
>>>
>>> Nick
>>>
>>> On Mon, Aug 13, 2012 at 11:32 AM, Trelle Sven <strelle@ctu.unibe.ch>
> wrote:
>>>
>>>> it might sound trivial but I was not able to find something in the
>>>> egen or extended macro function help:
>>>>
>>>> I want to create a new variable that contains the variable name that
>
>>>> holds the minimum value over several other variables per row i.e.
>>>> something like the "egen x= rowmin(y z w)" command but the created
>>>> variable should not contain the row minimum but the variable name
>>>> that contains this minimum.
*
*   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/


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