Statalist


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

st: RE: unexpected "ambiguous abbreviation"


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: unexpected "ambiguous abbreviation"
Date   Tue, 26 Feb 2008 18:43:05 -0000

Scalars and variable names share the same name space. That is in the
manual [P] 
and discussed at length within 

SJ-6-2  dm0019  . Stata tip 31: Scalar or variable? Problem of ambiguous
names
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  G. I.
Kolev
        Q2/06   SJ 6(2):279--280                                 (no
commands)
        tips for avoiding abbreviation conflicts with variables
        when naming scalars

What you want is 

tempname mu 
scalar `mu' = <whatever> 

Similarly, it is good practice to use tempnames for all scalars within
programs, unless you have 
a very good reason to the contrary. 

If you go 

tempname mu 
scalar mu = <whatever>

then that is legal, but makes no use of the tempname. 

If you use tempnames for all your scalars, there will be no clash
between scalar names and 
existing variable names, and no need to fiddle with whether variable 
abbreviation is on or off. In any case, note that if you have a scalar
mu 
and a variable name mu, then there is a clash regardless of whether
variable 
names can be abbreviated. In fact, I don't think you should mess with
variable 
abbreviation in most programs. 

Nick 
[email protected] 

Dirk Enzmann

Does somebody have an idea why I receive the error message "mu ambiguous

abbreviation" if the data contain variable starting with mu...? Below 
the result of trying to run my program "fitnb" with  - set trace on - 
and - set tracedepth 1 -.

I thought that using "tempvar mu" followed by "scalar mu = something" 
would result in mu being a temporary scalar (no macro!) existing only 
within the call of the program fitnb.

BTW, is there a possibility to check quietly the setting of varabbrev? 
So that I could use "set varabbrev off" at the beginning of the program 
and "set varabbrev on" at the end only if it has been "on" before (so 
that a call to the program will never change the setting "varabbrev" 
outside the program)? Because to use "set varabbrev off" is an effective

workaround.

Thanks in advance,
Dirk

=====================================================================
fitnb rbinz99
----------------------------------------------------- begin fitnb ---
- version 9
- syntax [varlist] [, maxval(integer 0)]
- tokenize `varlist'
= tokenize rbinz99
- args x
- tempvar x_max size mu N prob i nbdat maxfit pmisfit
- if `maxval'==0 {
= if 0==0 {
- local selection "if `x'<."
= local selection "if rbinz99<."
- }
- else {
   local selection "if `x'<. & `x'<=`maxval'"
   }
- sum `x' `selection'
= sum rbinz99 if rbinz99<.

     Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      rbinz99 |      9081    .2542672    2.124223          0        150
- scalar x_max = r(max)
- quietly nbreg(`x') `selection'
= quietly nbreg(rbinz99) if rbinz99<.
- scalar size = 1/exp(_b[/lnalpha])
- scalar mu = exp(_b[_cons])
- scalar N = e(N)
- scalar prob = size/(size+mu)
mu ambiguous abbreviation
------------------------------------------------------- end fitnb ---
r(111);
=====================================================================

-- 

*
*   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