Announcement

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

  • Bug Report: time-series operators / seasonal differencing

    Dear Statalisters,

    I detected a strange bug with the the seasonal differencing time-series operator. When I generate a new variable as
    Code:
    gen newvar = S0.oldvar
    newvar will actually not be the zeroth seasonal difference (which by definition should be a variable containing only zeros because oldvar is to be subtracted from itself) but the first seasonal difference of oldvar. When instead using the operator S0 with the summarize command, it produces the correct statistics (zero mean, variance etc.) but in the table it is labeled as S1.

    See the following example:
    Code:
    . webuse gxmpl1, clear
    
    . gen gnp_s0 = S0.gnp
    (1 missing value generated)
    
    . gen gnp_s1 = S1.gnp
    (1 missing value generated)
    
    . summarize gnp S0.gnp S1.gnp gnp_s0 gnp_s1
    
        Variable |       Obs        Mean    Std. Dev.       Min        Max
    -------------+--------------------------------------------------------
             gnp |
             --. |         8    6955.237      885.67     5837.9     8337.3
             S1. |         8           0           0          0          0
             S1. |         7    357.0571    94.32038   188.3999   485.3999
                 |
          gnp_s0 |         7    357.0571    94.32038   188.3999   485.3999
          gnp_s1 |         7    357.0571    94.32038   188.3999   485.3999
    
    . display "`: tsnorm s0'"
    S
    
    . display "`: tsnorm s1'"
    S
    
    . display "`: tsnorm s2'"
    S2
    As you can see, in the summarize table, S1.gnp appears twice in the first column but the statistics refer once to S0.gnp and once to S1.gnp. When first generating new variables, gnp_s0 = S0.gnp is actually generated identically to gnp_s1 = S1.gnp.

    I could confirm the problem with Stata versions 10, 11, 12, and 13, but I do not yet have access to Stata 14.

    While the operator S0 is actually of very limited practical relevance (because it always should result in a variable containing only zeros), it might happen in programming situations that someone generally codes something like S`n'.`varname', where the local macro n is determined somewhere earlier in the program, and due to whatever calculation this macro might evaluate to zero. In this case, subsequent results would become wrong.

    Edit: In Stata's help file for tsvarlist, Remark 7 states
    In operator#, making # zero returns the variable itself.
    This is meaningful for the operators L#, F#, and D#, but in my view not for S#. In any case, this is also not what is happening when using the operator S0.
    Last edited by Sebastian Kripfganz; 10 Apr 2015, 07:28.
    https://twitter.com/Kripfganz

  • #2
    Sadly, we agree, it's odd and a bug and we will fix it. We duplicated Thomas's report in both Stata 14 and 13! We will fix it in both. The Stata 14 updated will come out before the Stata 13 update.

    -- Bill Gould and Vince Wiggins

    Comment


    • #3
      Hi,
      I'm using Stata 15.1 and have found that using a seasonal difference operator s.x and a first-difference operator d.x give me the same results, no matter how I setup my time variable (quarterly, monthly, daily). I've looked for information on seasonal differencing but have come up empty handed. Is there a foundational document describing the s. operator and how to setup a panel or time-series dataset so that it works properly?

      Thanks
      Mike

      Comment


      • #4
        Hi Mike,

        You can find information on the time-series variable notation by typing in -help tsvarlist-. You'll notice that S.x and D.x produce the same "difference" when it's one time unit apart, but they will become different if you extend to D#.x vs S#.x. You can also find out how to declare data to be a time-series by typing -help tsset-.

        Comment


        • #5
          Thanks Leonardo!

          So it seems like seasonal differencing is not automatic, by which I mean Stata does not automatically subtract the appropriate same-past-season value. My assumption was that if data were tsset or xtset as monthly, then with s.x Stata would automatically do xt - xt-12. Obviously this must be entered by hand with s12.x.

          Thanks for your help!
          Mike

          Comment


          • #6
            That's correct, since Stata will not automatically know what a "season" is in your specific context (for example your data could be grouped by quarters, or a season may be 2 weeks long). You're welcome, Mike.

            Comment

            Working...
            X