Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Caution with set varabbrev off

    This post is in the nature of both a public service announcement for ordinary Stata users, as well as a plea to Stata Technical Services and perhaps also to KitBaum and authors who contribute commands to repositories like the SSC.

    As most users know, Stata by default permits you to abbreviate your variable names. This however, can sometimes lead to unexpected results in your code when you thought a variable abbreviation (say x) referred to one variable (say x1) but actually ends up referring to another (say x2). For this reason, many Stata style guides advise you to switch off this facility, by doing
    Code:
    set varabbrev off
    -- see for instance the World Bank DIME Analytics Stata Style guide, the CEU Microdata Stata style guide, Julian Reif's coding guide, Jonathan Shaw's 2014 list of "top ten Stata gotchas", among several others.

    I have personally followed this suggestion for some years now, and include the above setting in my profile.do file, which runs at the start of the Stata session.

    However, for those that use this setting, it is important to know that this setting may cause Stata code to throw errors (typically of the form variable <varname> not found) -- code that was written with the assumption that an abbreviation (say x) would suffice to reference a variable (say x1). Such code may of course occur in your own old do files and in files created by your collaborators, which is easy to fix.

    More seriously however, it may occur in community-contributed programs and commands that you may have downloaded from the Stata Journal or elsewhere: here is just one example.

    Even more seriously, it may occur in programs that are part of Stata's official codebase: here is a very recent example, to do with svmat.ado

    Equally troubling, the problem is rampant in code examples that are sprinkled throughout Stata's official documentation. I had flagged this a few months ago here.

    I request Stata Technical Services to please do a hygiene check of the documentation for examples and of the official codebase to ensure everything uses full variable names. It would also be great if authors of Stata commands could do similar hygiene checks before submitting their code for publication.

  • #2
    This is indeed an intermittent source of confusion. See also

    SJ-5-3 dm0016 . . . . . . . . . . . Stata tip 22: Variable name abbreviation
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . P. Ryan
    Q3/05 SJ 5(3):465--466 (no commands)
    tip for using set varabbrev to determine whether or
    not to allow variable abbreviations

    https://journals.sagepub.com/doi/pdf...867X0500500314

    Comment

    Working...
    X