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:
This gives me back the numbers 0 5 10 15 20.
But with some macro names I get very different results:
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.
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:
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).
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"
But with some macro names I get very different results:
Code:
nicenum longmacro = 0 20 di $longmacro * Result: 20
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
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
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).
Comment