It looks like you have too many " " in your -local- statement.
Your x macro looks like
" " " "make" " " "price" " " "mpg" " " "rep78" " " "headroom" "
" "trunk" " " "weight" " " "length" " " "turn" " " "displacement" " "
"gear_ratio" " " "foreign
Either simplify your -local- statement or bind it in another set of
quotes when you use -strpos-.
For example:
sysuse auto.dta,clear
foreach var of varlist _all {
local x "`x' `var'"
local x2 "`x2'" " " "`var'"
}
macro dir
di strpos("`x'", "price")
di strpos(`"`x2'"', "price")
Scott
On Jan 29, 2008 2:02 PM, Tim Wade <[email protected]> wrote:
> Hi Statalisters:
>
> I have a series of datasets with many variables but some variables are
> missing from some data sets. I would like to evaluate the data sets to
> see if certain variables are present before executing some code. My
> idea was to store all the names of the variables in a dataset in a
> macro variable, then evaluate that macro variable using "strpos" to
> see if the variable is present in the list, ending the code if strpos
> returns 0. However, "strpos" does not seem to be able to evaluate my
> macro variable. I have a feeling my problem may be the brute force way
> I am creating the macro (see below). When I manually create a local
> variable, it works fine. Can anyone suggest a better approach? Thanks
> much in advance for any suggestions!
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/