Bookmark and Share

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

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

st: run through every values of a variable

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


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






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


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index