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: keep if string for more variables


From   Nick Bornschein <[email protected]>
To   [email protected]
Subject   Re: st: keep if string for more variables
Date   Wed, 11 Dec 2013 09:23:11 +0100

Sorry for the misleading details:

I have one string variable (question) with string information like blue01 blue02 yellow01 and so on. So that's why I tried to use

keep if question == "blue*"

which did not work.

-Nick



Am 10.12.13 17:26, schrieb Nick Cox:
No; the question is

"keep all blue data"

and the only uncertainty is whether Nick B is talking about syntax to
select variable names or syntax to select string values.

Nick
[email protected]


On 10 December 2013 16:14, Sergiy Radyakin <[email protected]> wrote:
if blue01..blue10 are dummies, then to keep 'any blue' one might say:

clear
set obs 100
forval v=1/10 {
   generate byte blue`v'=runiform()>0.95
}

egen flag=rowtotal(blue1-blue10)
keep if flag
drop flag

list

Best, Sergiy

On Tue, Dec 10, 2013 at 10:55 AM, Red Owl <[email protected]> wrote:
My suggestion below assumed you have a single string variable named
color with values blue01, blue02, yell0w01, etc.

If you have a set of binary variables for various colors, the solution
would be different.



Red Owl <redowl@liu> wrote:

Try:

keep if substr(color,1,4)== "blue"

Red Owl
[email protected]


Nick Bornschein <[email protected]> wrote:

Hi,

I have string variables, blue01 to blue10 and yellow01 to yellow10. I
want to keep some data by using:


keep if color == "blue*" to keep all blue data, but it does not work.
Any idea?


Thanks a lot
-Nick
*
*   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/

*
*   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