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: scalar and others...

From   Christopher Baum <>
To   "" <>
Subject   Re: st: scalar and others...
Date   Mon, 4 Jun 2012 08:41:34 -0400

On Jun 4, 2012, at 8:33 AM, Tashi wrote:

>    I am reading An Introduction to Stata Programming. I came across with this thing and I am not too sure I understood.
> 1. the author recommends using built in functions to interpreted codes like egen. Could someone tell me what is an interpreted code and how is it different from built in codes like generate and replace?
> 2. I read somewhere(sorry for vaguness) that  scalar is global in scope yet the book doesn't mention about it while describing scalar. I guess my question is if scalar is local or global in scope?

Items that appear under -help functions- are compiled functions (written in C) which will run faster than similar functions available via -egen-. Recently I translated some code that an inexperienced programmer had written as 

egen sigma = total(X)

rather than using

summ sigma, meanonly

The latter will produce the sum of the series (r(sum)) much more rapidly, and will not repeat the same value _N times in a variable. The egen total() function is useful under by-control, but should not be used over the whole sample. 

2. scalars, like Stata variables, have global scope. Once you define a scalar, it sticks around. That's why in an ado-file (or even in a do-file) where you may be concerned about namespace collisions, you should use -tempname- to create scalars that will then not have the same names as earlier references in the same Stata session.


Kit Baum   |   Boston College Economics & DIW Berlin   |
                             An Introduction to Stata Programming  |
  An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

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