try:
foreach var of varlist `r(varlist)' {
That is: adding a "`" and a "'" around r(varlist)
Hope this helps,
Maarten
--- "Jennifer S. Earl" <[email protected]> wrote:
> In the middle of a program I am working on, I need to set a bunch of
> variables to missing, some of which are numeric and some of which are
>
> string. Since the replace command is sensitive to numeric or string,
> I need
> to do separate foreach loops.
>
> Here is what I have tried:
>
> ds , has(type numeric)
> local num_vars r(varlist)
> foreach var of local num_vars {
> replace `var'=. if `var'_error==1
> }
>
> ds , has(type string)
> local string_vars r(varlist)
> foreach var of local string_vars {
> replace `var'="" if `var'_error==1
> }
>
> Unfortunately, when I try this, I get the following error:
> time-series operators not allowed
> r(101);
>
> If I do instead (in case if is my foreach line that is giving me
> problems):
> ds , has(type numeric)
> local num_vars r(varlist)
> foreach var of local `num_vars' {
> replace `var'=. if `var'_error==1
> }
>
> I get the following error:
> { required
> r(100);
>
> But, the puzzling part is that I see the right list of numeric
> variables
> displayed if I do:
>
> ds , has(type numeric)
> local num_vars r(varlist)
> display `num_vars'
>
> So, I know I am fetching the right list, I am just not able to
> operate on
> it in the foreach loop.
>
> I have tried other ways of selecting off just the numeric variables
> and
> just the string and none are working.
>
> Any suggestions? Maybe it is late and I missing something obvious?
>
> Cheers,
>
> Jenn
>
> *********************************
> Jennifer Earl
> Director, Center for Information Technology and Society
> Associate Professor of Sociology
> University of California, Santa Barbara
> Santa Barbara, CA 93106-9430
>
> P: (805) 893-7471
> F: (805) 893-3324
> *********************************
> *
> * 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/
>
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
Send instant messages to your online friends http://uk.messenger.yahoo.com
*
* 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/