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: Problem with wildcards


From   "Dimitriy V. Masterov" <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Problem with wildcards
Date   Mon, 4 Mar 2013 13:52:10 -0800

This will not quite treat missings the way that you want, but you can
use rowtotal() to take care of that case if that is indeed what you
want.

DVM

On Mon, Mar 4, 2013 at 1:48 PM, Dimitriy V. Masterov <[email protected]> wrote:
> Lisa,
>
> The reason that does not work is that it evaluates to
>
> replace anypsych = 1 if psych1 psych2 ... psych42 == 1
>
> That is is not valid syntax.
>
> You could use egen (extended generate) to do this:
>
> egen anypsych = rowmax(psych1 - psych42)
>
>
> DVM
>
> On Mon, Mar 4, 2013 at 1:36 PM, Lisa Cook <[email protected]> wrote:
>> Hi,
>>
>> I'm having a problem using wildcards. I'm using Stata 11.2 for Windows.
>>
>> I have a list of variables: psych1 - psych42. I would like to create a
>> new variable called "anypsych" that takes the value of 0 if all the
>> variables psych1-psych42 are 0 or missing, and takes the value 1 if
>> any of psych1-psych42 are 1.
>>
>> My code:
>>
>> gen anypsych = 0
>> replace anypsych = 1 if psych* == 1
>>
>> I get the error "psych* invalid name".
>>
>> Can anyone tell me why it's an invalid name and how I can achieve this
>> objective? I also have a bunch of other variables that I need to do
>> the same thing for, so advice on how to approach this would be a huge
>> help.
>>
>> Thanks!
>> Lisa
>> *
>> *   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