Statalist


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

Re: st: local macro tempvar troubles


From   [email protected] (Jeff Pitblado, StataCorp LP)
To   [email protected]
Subject   Re: st: local macro tempvar troubles
Date   Wed, 03 Oct 2007 16:05:16 -0500

Timothy Dang <[email protected]> is working with an -ml- evaluator program
and is getting a "too few variables specified" error:

> I'm using Stata/IC 10.0 on a Mac, just in case that matters.
> 
> I'm writing a .do file using -ml- . I don't think that matters, but in
> any case, in the likelihood program I generate a lot of temporary
> variables, like so:
> -----
>     tempvar prHeart prSpade prClub prDmd
>     tempvar valMix valHt valSpd valClub valDiamond
>     tempvar MixLove expHeart expSpade expClub expDiamond expSum
> 
> 	gen double `prHeart'=0
> 	gen double `prSpade'=0
> 	gen double `prClub'=0
> 	gen double `prDmd'=0
> 	gen double `valMix'=0
> 	gen double `valHt'=0
> 	gen double `valSpd'=0    // concentrate on this line
> 	gen double `valClub'=0
> 	gen double `valDiamond'=0
> -----
> 
> On the line which says "gen double `valSpd'=0", it originally said
> "gen double `valSpade'=0". There was trouble with that, though. When I
> ran the program, it appeared that `valSpade' was null--it replaced the
> line with "gen double =0".
> 
> I "fixed" the problem by doing a search/replace all from "valSpade" to
> "valSpd". For some reason, that actually DID fix the problem. Now, the
> same thing is happening with the last line above. For the valSpd line
> it's nicely doing "gen double __00000S=0". For "gen double
> `valDiamond'=0" it makes "gen double =0", causing the error: "too few
> variables specified".
> 
> This kind of problem has been dogging me this evening, with different
> variable/macro names being the trouble. I'm flummoxed. Anyone know
> what I'm foolishly overlooking?

Nick Cox and Michael Hanson replied, mentioning the possibility of a typo or
invisible characters.

Another possibility is that Timothy's -ml- evaluator program is either missing
a -version- statement or has a -version- statement that specifies a version of
6 or less.  Here is the relevent entry in -help version- the describes a
possible cause for the above behavior:

1.  macro substitution is made on the basis of the first 7 (local) or
    8 (global) characters of the name; `thisthatwhat' is the same as `thistha'

The problem is that in modern Stata's (since Stata 7), the command

	tempvar valDiamond

generates a local macro named "valDiamond" not "valDiam", but the macro
expanding logic under version 6 (or less) is treating `valDiamond' as
`valDiam'.

I suspect that Timothy's -ml- evaluator function is lacking a -version-
statement.  If so he can just add 

	version 10

as the first line in his program definition.  For example,

	program myeval
		args lnf xb1 xb2 ...
		...
	end

should be

	program myeval
		version 10
		args lnf xb1 xb2 ...
		...
	end

Now Timothy can use tempvars with local macro identifies that are more than 7
(up to 31) characters long.

--Jeff
[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/



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