Bookmark and Share

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

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

Re: st: tempvar versus tempname

From   Nick Cox <>
To   "" <>
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'"

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.


On 29 October 2013 23:56, David Rivenbark <> 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:
> *
> *
> *
*   For searches and help try:

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