Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: store variable names in local macro


From   "Scott Merryman" <[email protected]>
To   [email protected]
Subject   Re: st: store variable names in local macro
Date   Tue, 29 Jan 2008 14:20:06 -0600

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index