Announcement

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

  • Macros r() deleted when dropping a variable in Stata 15.1

    Dear Listers,

    just stumbled over this:
    When dropping a varaible in Stata 15.1, previously returned macros r() are deleted.
    So, if I do the following code, Stata 15 displays a missing after the last line, whereas Stata 14 displays the mean value.

    set obs 100
    ge bla=runiform()
    su bla
    di r(mean)
    drop bla
    di r(mean)

    Don't know if that's wanted, but might cause problems with older do-files (and ados).

    Volker


  • #2
    This is because, unlike earlier versions of Stata, current Stata returns r(k_drop), the number of variables dropped,when the -drop- command is run. In this regard, it is like any other command: if it returns something in r(), previous contents of r() go out of scope.

    Older do-files and ados might indeed break over this, but not if they are run under version control. Try running the exact same code, preceded by -version 15.0- (or any older version) and you will see that the value of r(mean) remains available.

    Comment


    • #3
      Thanks Clyde, that does make sense.

      Comment


      • #4
        If you want to avoid invoking version control every time, try something like

        Code:
        program mydrop
            version 15
            drop `0'
        end
        for any suitable value of 15.

        Comment

        Working...
        X