Announcement

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

  • Unexpected results from -nicenum-

    I've noticed some behaviour with -nicenum- that strikes me as odd. Specifically, the results that it returns seem to depend on the name of the global that I feed it, and also the order in which I run the commands.

    For the most part it seems to work fine, and returns the numbers I'm expecting:
    Code:
    nicenum demo = 0 20
    di $demo
    di "$demo"
    This gives me back the numbers 0 5 10 15 20.

    But with some macro names I get very different results:
    Code:
    nicenum longmacro = 0 20
    di $longmacro
    * Result: 20
    This seems to be partly about the length of the macro name, with names of over eight characters giving unexpected results. But the particular unexpected results seem to depend on the order of the commands.
    Code:
    clear all
    macro drop _all
    
    // Long macro name
    nicenum longmacro = 0 20
    di $longmacro
    * Result: 20
    
    // Eight-character macro name
    nicenum longmacr = 0 20
    di $longmacr
    * Result: 0 5 10 15 20
    
    // Long macro name again
    nicenum longmacro = 0 20
    di $longmacro
    * Result: 0 5 10 15 20 20
    This seems to be about more than just issues overwriting a global that's already been defined. I get different answers depending on which commands I've run previously:
    Code:
    // Start with the long macro name
    clear all
    macro drop _all
    nicenum longmacro = 0 20
    di $longmacro
    * Result: 20
    
    // Start with the eight-character macro name
    clear all
    macro drop _all
    nicenum longmacr = 0 20
    di $longmacr
    * Result: 0 5 10 15 20
    
    nicenum longmacro = 0 20
    di $longmacro
    * Result: 0 5 10 15 20 20
    And this holds even when I open up a new session of Stata between them.

    Obviously, this isn't really a 'problem' since I can just use shorter macro names that seem to work. But it took me a while to figure out why I was getting strange results some of the time, and that made me curious about what's behind this behaviour. So I thought it might be worth (a) documenting and (b) asking whether anyone can shed any light on what's driving this?

    *** Technical details ***
    I'm using Stata version 14.2 on Windows 7 Professional.
    -nicenum- is written by James W. Hardin and is available via -findit nicenum- (package number dm28).

  • #2
    I note that nicenum was written for Stata 4.0. It might be worth your while cloning the program and changing the version statement. I can't guarantee that won't break something else.

    Comment


    • #3
      Thanks for the suggestion! Unfortunately it looks like I'm still getting the same results when I update the program's version to 14.2.

      Comment

      Working...
      X