Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: tempvar versus tempname


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: tempvar versus tempname
Date   Wed, 30 Oct 2013 00:15:52 +0000

-tempvar- is, as I understand it, part psychology, part syntax.

You are just asking for a temporary name and indicating to whoever
reads the program, not least yourself, that you _intend_ to create a
variable and use that name. If you lie, and never create that variable
or use the name for some other purpose, that in itself is not illegal
or fatal.

However, nothing is created until you use -generate- later, directly
or indirectly.

A temporary name has various characteristics. It is referred to by a
local macro with the name you supply, which holds a legal Stata name
starting with two underscores and ending with 6 digits which are
guaranteed not to be in use at the moment. When your program ends,
Stata drops any such variables or scalars.

As variables and scalars share the same name space, you could use
-tempname- to the same end, and vice versa:

. tempvar foo

. scalar `foo' = 42

. scalar list
__000000 =         42

. di "`foo'"
__000000

It is, however, likely to be considered poor style to use -tempvar-
when you are creating scalars, and good style to use -tempvar- when
creating variables.

Nick
[email protected]


On 29 October 2013 23:56, David Rivenbark <[email protected]> wrote:
> Hi all:
>
>         I have a simple user defined likelihood function that has the
> following form
>
> Program my_lf
>
>         args lnfj theta1 theta2
>         tempname xb sigma
>         tempvar tmp1 tmp2 ....
>
>         gen double `xd' = `theta1'
>         gen double `sigma' = exp(`theta2')
>
>         ...
>
>         replace `lnfj' = ...
>
> end
>
> My model also assumes that `theta1' has of two independent variables x1 and
> x2.
>
>         I noticed that the results for my model are unchanged by using
> -tempname- or -tempvar-. I assume this is because I specify "gen double `xb'
> = `theta1'" Has anyone else noticed this before?
>
> David
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index