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


From   Lisa Cook <hlthsrvcsphd@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Problem with wildcards
Date   Mon, 4 Mar 2013 18:09:32 -0500

Thank you, Dimitriy and Daniel.

I'd be very interested in understanding the
differences/benefits/drawbacks between these two approaches, if
someone could explain them to me.

*off to read about rowmax and rowtotal*,
Lisa

On Mon, Mar 4, 2013 at 4:48 PM, Dimitriy V. Masterov <dvmaster@gmail.com> wrote:
You could use egen (extended generate) to do this:

egen anypsych = rowmax(psych1 - psych42)

AND

On Mon, Mar 4, 2013 at 6:01 PM, daniel klein <klein.daniel.81@gmail.com> wrote:
> Here is my approach.
>
> unab psych : psych1-psych42
> loc psych : subinstr loc psych " " ", " ,all
> g byte anypsych = inlist(1, `psych')
>
> Best
> Daniel
>
> --
> 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.
*
*   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