Statalist


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

Re: st: RE: local macro tempvar troubles


From   "Timothy Dang" <[email protected]>
To   [email protected]
Subject   Re: st: RE: local macro tempvar troubles
Date   Wed, 3 Oct 2007 05:20:53 -0700

Hi Nick & all-

Considering how odd it seemed to me, I made sure to cut & paste my
actual code (I did cheat and add the "// concentrate on this line"
comment after pasting).

In any case, things are working at the moment. I still don't know what
to think. I have had similar problems in the past in other software
when invisible characters or invisible differences between characters
caused things which looked identical to me to be different for the
software. That doesn't seem like a good explanation here because (1)
it seems an unlikely feature of the Stata do-editor, and (2) search &
replace also thought things were identical.

Thanks for the thoughts. It seems likely the problem will come up
again, and if it does I'll see what I can do to better pin it down.

-Timothy

On 10/3/07, Nick Cox <[email protected]> wrote:
> I get the impression this isn't your real code.
>
> The essence of what I think is biting you can
> be seen in
>
>         clear
>         set obs 100
>         tempvar frog
>         gen `frog' = 0
>         gen `toad' = 0
>
> If you run this, generation of `frog' will
> work, but not that of `toad'. Why not?
>
> 1. Local macros that have not been defined
> are treated as empty (null). Referring to
> a local macro that does not yet exist is
> not in itself an error, but its consequences
> may be. In this case, `toad' does not exist,
> so Stata sees
>
>         gen = 0
>
> which is illegal in Stata. Specifying a
> -double- type does not affect this issue.
>
> 2. You have two ways of declaring a local
> macro to Stata. You can explicitly define
> one
>
>         local answer "Stata"
>         local answer = 42
>
> When you do that you specify name (answer)
> and contents (whatever they are) in one go.
>
> Alternatively, you can flag that you
> will be using a macro with a particular
> name.
>
>         tempname toad
>
> flags that you will be referring to `toad'
> later in your program. Stata will create a unique name
> and let you use `toad' as an alias for it.
> In your case you want to create a temporary
> variable, so the alternative
>
>         tempvar toad
>
> makes your intention even clearer.
>
> In your example you had a typo that you found.
> It's my bet, although it's not obvious from
> your example, that in your real code there is at
> least one other typo. It's likely to be more subtle than
> the difference between `frog' and `toad'. But it will
> be there.
>
> In well-developed text editors, you will have a command that
> lets you search for the identifier under the cursor,
> or that in equivalent terminology. So, this kind of error is
> easier to spot in a good editor.
>
> Nick
> [email protected]
>
> Timothy Dang
>
> > 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?
>
> *
> *   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/
>


-- 
------------------------------
Timothy O'Neill Dang / Cretog8
623-587-0532
One monkey don't stop no show.
*
*   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