Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: tokenize `varlist' error?


From   David Kantor <dkantor@jhu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: tokenize `varlist' error?
Date   Fri, 23 Apr 2004 12:25:00 -0400

At 11:15 AM 4/23/2004 -0400, Adrian Gonzales wrote:

Dear Statalisters

I want to perform a simple procedure over 100 variables and I don t want to enter the name of each variable one by one.

If I use the first definition of varlist (below), my little procedure works fine. But if I used the second definition of varlist, using - I get an error (procedure below).

How can I solve this problem? I am sure this is very simple for most of you, but I am new trying to do these things with Stata.
[...]


local varlist p26_1_1 p26_1_2 p26_1_3

local varlist p26_1_1-p26_1_3

tokenize `varlist'

[...]

The first version of varlist contains actual variable names, so -tokenize- works fine. The second is an abbreviated list; it does not literally contain all the variables you want, plus it has a hyphen, which is not legal in variable names.

What you want is -unab-, rather than -tokenize-.

Better yet, if this is in a program, use -syntax-.

Also, you might want to use -foreach- instead of -while- (does Stata 7 have -foreach- ?).

Good Luck.
-- David


David Kantor
Institute for Policy Studies
Johns Hopkins University
dkantor@jhu.edu
410-516-5404

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index