Announcement

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

  • Declaring data to be time-series data

    Hi everyone!

    I have monthly data set presented as such

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long yyyymm double return
    187101  .01242389
    187102  .02019115
    187103  .02964644
    187104  .03405454
    187105  .02848361
    187106 -.01542547
    187107 -.00863808
    187108  .01915629
    187109  .01136751
    187110 -.05886838
    187111  .03742423
    187112   .0257288
    187201  .02951672
    187202  .00101633
    187203  .04072984
    187204  .03142682
    187205 -.00213872
    187206 -.00795212
    187207 -.00034236
    187208 -.00761387
    187209 -.01335902
    187210  .01832136
    187211 -.00212152
    187212  .03346823
    187301  .01082923
    187302  .01575765
    187303 -.01307993
    187304 -.00878622
    187305  .01496919
    187306 -.01535528
    end
    format %tm yyyymm

    First i tried to simply use
    Code:
    tsset yyyymm, monthly
    
    time variable:  yyyymm, 1.9e+05 to 2.0e+05, but with gaps
                    delta:  1 month
    But as you can see i get weird numbers out

    I also tried do this:
    Code:
     . gen date = ym(floor( yyyymm/100 ), mod( yyyymm, 100 ))  . format date %tm  . tsset date, monthly         time variable:  date, 1871m2 to 1873m7                 delta:  1 month
    But later when i try to do:
    Code:
    newey return L.return, lag(10)
    I get this syntax date is not regularly spaced

    Any idea on what i should do in this situation? Thank you all in advance
    Last edited by Filip Pierzgalski; 28 Jan 2019, 05:00.

  • #2
    Your first approach was clearly wrong, as you don't have monthly data that are 187101 or more months from 1 January 1960, i.e. roughly 15,000 years into the future.

    The second approach is clearly right, but I can't reproduce your problem with Stata 15.1.

    Code:
    . gen date = ym(floor( yyyymm/100 ), mod( yyyymm, 100 ))  
    
    . format date %tm  
    
    . tsset date, monthly        
            time variable:  date, 1871m1 to 1873m6
                    delta:  1 month
    
    .
    . newey return L.return, lag(10)
    
    Regression with Newey-West standard errors      Number of obs     =         29
    maximum lag: 10                                 F(  1,        27) =       0.02
                                                    Prob > F          =     0.8986
    
    ------------------------------------------------------------------------------
                 |             Newey-West
          return |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          return |
             L1. |   .0146226   .1136528     0.13   0.899    -.2185736    .2478188
                 |
           _cons |   .0084265   .0026522     3.18   0.004     .0029847    .0138683
    ------------------------------------------------------------------------------
    That's a small sample to do much with, as presumably you realise.

    (If you aren't using Stata 15.1, you should tell us that. https://www.statalist.org/forums/help#version applies.

    Comment


    • #3
      There is something wrong here, and I do not see what it is.

      You are correctly specifying your data as Stata monthly elapsed date. You might be even using a solution that I came up with at some point here ( https://www.statalist.org/forums/for...perfectly-fine ).

      Then when you -tsset- your data, your command does not report any irregularities, it says delta is 1 month, it does not say irregularly spaced... But then -newey- claims that your data is irregularly spaced. This does not sound right. It sounds like this cannot be. Also this problem does not occur in the data that you apply with -dataex- above.

      The only explanation that I can think of is that something has gone wrong with your data between the -tsset- command, and the -newey- command.

      Comment


      • #4
        Thank you for super fast answer, i'm using stata 15.1. I did exactly the same procedure, and i don't get the table
        Code:
        . gen date = ym(floor( yyyymm/100 ), mod( yyyymm, 100 ))
        
        . format date %tm
        
        . tsset date, monthly
                time variable:  date, 1871m1 to 2017m12
                        delta:  1 month
        
        . newey return L.return, lag(10)
        date is not regularly spaced
        r(198);

        Comment


        • #5
          #1 reports an error message that can't be reproduced for the example data only.

          Now #4 reports an error message for data from 1871 to 2017 which we can't access.

          You still need to show us a problem we can reproduce.

          NOTE: Cross-posted at https://stackoverflow.com/questions/...eries-in-stata Our policy on cross-posting is explicit. You are asked to tell us about it.

          Comment


          • #6
            I also tried simply doing this:

            Code:
            . gen t=_n
            
            . tsset t
                    time variable:  t, 1 to 1764
                            delta:  1 unit
            
            . newey return L.return, lag(10)
            t is not regularly spaced
            r(198);
            t is number from 1 to 1764, so how can this be not regulary spaced??

            Comment


            • #7
              I was missing 4 observation, it worked perfectly when i dropped them! Thank you for the help that i have recieved
              Last edited by Filip Pierzgalski; 28 Jan 2019, 05:53.

              Comment


              • #8
                Again, what you are doing is correct, and I often do this when I do not feel like fighting Stata dates, which I have found to be formidable foes.

                Code:
                . sort yyyymm
                
                . gen mydate = _n
                
                . tsset mydate
                        time variable:  mydate, 1 to 30
                                delta:  1 unit
                
                . newey return l.return, lag(10)
                
                Regression with Newey-West standard errors      Number of obs     =         29
                maximum lag: 10                                 F(  1,        27) =       0.02
                                                                Prob > F          =     0.8986
                
                ------------------------------------------------------------------------------
                             |             Newey-West
                      return |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                      return |
                         L1. |   .0146226   .1136528     0.13   0.899    -.2185736    .2478188
                             |
                       _cons |   .0084265   .0026522     3.18   0.004     .0029847    .0138683
                ------------------------------------------------------------------------------
                And again this problem does not arise in the data you attached with -dataex-, and again I cannot explain from where the problem comes. Such a problem should not occur.

                Can your -newey- ado be messed up for some reason? Why dont you try some other time series command that needs tsset to see whether the problem is not with -newey-?

                Comment


                • #9
                  We can't help further, I guess, unless you post a complete reproducible example with the entire dataset that yields it. Use the options of dataex to override the default sample size.

                  EDIT: A revision to #7 appears to close the thread.
                  Last edited by Nick Cox; 28 Jan 2019, 06:13.

                  Comment

                  Working...
                  X