Wednesday, December 12, 2007

Using Macros in STATA

If you are programming in Stata, or using macros for any reason, be careful when squaring.
Try the following if interested (commands in italics), though you can see the result:

gl check = -.01
di $check-.01

di $check^2
-.0001
di ($check)^2
.0001

This was done on Stata 8.2 but I also found this to issue on Stata 9.

1 comment:

dherberich said...

Turns out there is an understandable reason for this. The macros are read before any operation is done, then the order of operations places ^ before -. Good to know though.