Matt Dobra
> Thanks! I had a problem because I forgot the left and right
> apostrophes, and now i've figured out where I went awry. While this
> works, I must admit I'm a bit confused. I guess I never thought
> there was a difference between r(varlist) and "`r(varlist)'", and
> I'm still not sure why adding the quotes changes what is displayed.
There is a large society of Stata programmers who ever got
confused by this. You've just joined, and mine's an orange juice.
Suppose you
. ds
and want to pick up the r(varlist) it leaves behind.
. local list = r(varlist)
works properly if and only if the length of the string in
r(varlist) is at most 244 characters (in Stata/SE 8).
See help on -limits-.
The symbol = instructs Stata to _evaluate_ the expression
following and there's a limit on how long that expression
that be. This is nothing to do with r(varlist) as such.
. local list "`r(varlist)'"
on the other hand just copies the result of substituting
the local macro.
In other words, r(varlist) has a variety of guises.
At one extreme, it is almost a weird kind of function, except that
it only produces whatever result was last put in it.
At another, it's the name of a special kind of local macro.
Or at least it seems that way.
> p.s. I tokenize for the pure joy of tokenizing!
>
> Actually, I tokenize so I can later randomly choose variables to
> include in an estimation. My code was working fine, except when I
> had collinear variables. However, stata treats collinearity
> differently between ml procedures and regression procedures. If I
> want to randomly choose variables to include in an ml procedure, say
> probit, my program produced different types of errors when I
> randomly chose collinear variables than in, say, OLS.
>
> If, for example, x1=x2, and I type:
> . reg y x1 x2
> The output table says x2 was dropped and if I type:
> . di _b[x2]
> it tells me:
> 0
>
> Conversely, if I type:
> . probit y x1 x2
> Before anything is done, stata drops x2 and if I type:
> . di _b[x2]
> it tells me I made an error of the 111 variety:
> [x2] not found
>
> Both of these create different problems, so I want to simply remove
collinear
> variables before I start.
OK. Another way to do that, if I understand correctly, is to
generate a random integer # and then plug that in to
local var : word # of `r(varlist)'
Nick
[email protected]
*
* 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/