Announcement

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

  • Unexpected behavior of FVREVAR: bug or intended?

    Dear Statalisters,
    Before I bother the technical support of StataCorp, I would like to hear your opinion about the following behavior of fvrevar.

    When I call fvrevar once with a variable name that contains time-series operators, it creates a new temporary variable with the same values as the original. This is expected.

    When I subsequently call fvrevar again with the same original variable name, it does not create a new temporary variable but instead returns the name of the previously created temporary variable. This becomes problematic when I modify the content of this temporary variable before calling fvrevar the second time, or simply when I need two different temporary variables for subsequent computations.

    Here is an example:
    Code:
    clear all
    webuse abdata
    
    program fvrevar_test
        syntax varname(num ts)
    
        // varlist refers to variable L.n
        // fvrevar creates temporary variable __000000 identical to L.n
        fvrevar `varlist'
        loc newvarname "`r(varlist)'"
        sum `varlist' `newvarname'
    
        // content of only the temporary variable __000000 is modified
        replace `newvarname' = 0
    
        // varlist still refers to original unchanged variable L.n
        // fvrevar attempts again to create the temporary variable __000000 (instead of __000001)
        // "new" temporary variable has the same values as the previously modified temporary variable (bug?)
        fvrevar `varlist'
        loc newvarname "`r(varlist)'"
        sum `varlist' `newvarname'
    end
    
    fvrevar_test L.n
    The output is as follows:
    Code:
    . fvrevar_test L.n
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
               n |
             L1. |        891    1.083518    1.338469  -2.095571   4.687321
                 |
        __000000 |        891    1.083518    1.338469  -2.095571   4.687321
    (1,031 real changes made)
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
               n |
             L1. |        891    1.083518    1.338469  -2.095571   4.687321
                 |
        __000000 |      1,031           0           0          0          0
    I expected that the second call of fvrevar would create a new temporary variable _000001 with the values of the original variable L.n, not again _000000, because I want to do different things with the two temporary variables.

    I would call this a bug, but maybe there is a reason for this behavior that I do not see?!
    https://www.kripfganz.de/stata/

  • #2
    Not a bug; documented behavior in [R] fvrevar on p. 838, Techincal note. Implemented for good reasons, yet inconvenient at times, as reported here.

    Best
    Daniel

    Comment


    • #3
      Thanks Daniel, I should have read the documentation more carefully. I still find this behavior of fvrevar annoying but there are of course ways to work around this problem now that I am aware of it.
      https://www.kripfganz.de/stata/

      Comment

      Working...
      X