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]

st: run through every values of a variable


From   tashi lama <[email protected]>
To   <[email protected]>
Subject   st: run through every values of a variable
Date   Thu, 3 May 2012 19:02:41 +0000

Hello, 

    I have a variable broker_id in my dataset as follows...

broker_id 

6429

131

244

 

and I have to see if "555" matches any of the values in a broker_id. Now, I think I could use some technique like 

 levelsof broker_id, clean 

 capture confirm var "555" 

 

but I am wondering if there is a st. forward way to do this using forvalues loop like this

 

1. When I did forvalues i=1/_N {

                   if broker_id[`i']=="555" {

                    ........

 

I get invalid syntax. I am not so sure... Could someone explain?

 

2. I see that Nick has given a way to do this in stata resource and support page 

sysuse auto      

foreach i in 0 1 {
 whatever if foreign == `i'

}

  I tried to run this and got unrecognized command whatever in return. Is it because whatever is an obsolete command? Any idea....


Thanks, 

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