Announcement

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

  • Not obvious behavior

    The following fragment illustrates a rather non-obvious behavior of Stata when working with data frames.
    Upon closer inspection it doesn't look like a bug, but nevertheless shows that if you only need to run a single command on a different frame the choice between the following two matters:
    • :
    • { }
    Code:
    clear all
    version 16.0
    sysuse nlsw88
    tempname tmp
    frame create `tmp'
    display `"`: label occlbl 1'"'
    frame default: display `"`: label occlbl 1'"'
    frame `tmp' : {
      frame default: display `"`: label occlbl 1'"' 
      frame default {
        display `"`: label occlbl 1'"' 
      }
    }
    The reason why the highlighted line works differently is because the macro expansion is still evaluated in the context of the current frame, and then the result is passed to the default frame. The subsequent three lines work differently: the current frame is changed first, then the macro is evaluated, then the frame is changed again.

    Best, Sergiy Radyakin
Working...
X