Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: still for Stata 14: a new cases function complementing cond and recode


From   László Sándor <[email protected]>
To   [email protected]
Subject   Re: st: still for Stata 14: a new cases function complementing cond and recode
Date   Thu, 12 Sep 2013 18:20:35 -0400

Thanks, Billy.

I think no function can multiple values to a single value, that is a
correspondence.

Your example is about assigning the same value to multiple values. OK,
it would not replace the labelling and other functions or recode.ado,
but the function could still work as I wrote.

Even more, the existing recode() function is better suited for what
you wrote already.

I would still consider the following useful:

gen newrep77 = cases(inlist(rep77,1,2),1,rep77==3,2,inlist(rep77,4,5),3).
Repeating the variable name is a pain, but still better than nesting
conds. And there can be legitimate cases where some conditions refer
to other variables than others, e.g. if you want to assign marginal
tax rates to individuals based on income and demographics.

Also, the command or function distinction was intentional, it is
meaningful. E.g. there is a recode command and a recode function.

Laszlo

On Thu, Sep 12, 2013 at 6:04 PM, William Buchanan
<[email protected]> wrote:
> So what would you do in the case where you needed to assign multiple values to a single value?  From the recode help file:
>
> webuse fullauto, clear
> recode rep77 rep78 (1 2 = 1 "Below average") (3 = 2 Average) (4 5 = 3 "Above average"), pre(new) label(newrep)
>
> And changing the way that you interact with the code (e.g., the command/function that you call) does not necessarily imply restructuring the architecture of the underlying program, so there is no reason that this would be any faster/slower than what is already in place.  So I fail to see how your suggestion would render "the ridiculously slow -recode- command obsolete."
>
>
> Billy
> On Sep 12, 2013, at 4:29 PM, László Sándor <[email protected]> wrote:
>
>> It would be nice to have a "cases" function built in, instead of
>> resorting to nested conds as the only, unpopular alternative to many
>> lines of "replace if"s following an initial -gen-. Way too many
>> processor hours are wasted worldwide on not having a function like
>> -recode()- but only slightly complicated:
>> cases(condition1,value1,condition2,value2,…,value_if_none_true)
>>
>> Btw, this would also make the ridiculously slow -recode- command obsolete.
>>
>> Thanks,
>>
>> Laszlo
>>
>> *
>> *   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/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index