Announcement

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

  • Questions on r(198)

    Dear all,

    I am trying to use the Newey-West Standard Errors to carry out my regression, however, the following popped up:

    Code:
    . newey  csad c.abs_r_mt##c.abs_r_mt, lag(1)
    date is regularly spaced, but does not have intervals of 1
    r(198);
    Below is my -dataex-:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int date float(csad r_mt year abs_r_mt)
    15347         .          . 2002          .
    15354  4.150988  -8.779794 2002   8.779794
    15361   8.47286 -11.722405 2002  11.722405
    15368  2.371604   .7411363 2002   .7411363
    15375  4.922579  12.524622 2002  12.524622
    15382  1.898078 -.10467237 2002  .10467237
    15389         0          0 2002          0
    15396  1.229306  1.9515274 2002  1.9515274
    15403  2.176993 -.24670455 2002  .24670455
    15410  5.491458  11.407248 2002  11.407248
    15417  3.275471 -2.9843094 2002  2.9843094
    15424  2.618778   2.722045 2002   2.722045
    15431  3.072469  -3.339813 2002   3.339813
    15438    2.6599  1.5941483 2002  1.5941483
    15445    2.7624   .7426223 2002   .7426223
    15452  2.954676 -1.6689825 2002  1.6689825
    15459  3.800143   2.567357 2002   2.567357
    15466 1.5627458   .2256331 2002   .2256331
    15473 2.2163022 -2.0939267 2002  2.0939267
    15480 2.4541366  -4.799683 2002   4.799683
    15487 3.1900074   1.408269 2002   1.408269
    15494 3.8380544  -4.929328 2002   4.929328
    15501 2.5736775  2.7708454 2002  2.7708454
    15508 1.8126394  -1.549638 2002   1.549638
    15515  4.617593   14.62258 2002   14.62258
    15522 3.7301376 -2.0095348 2002  2.0095348
    15529 2.0474093  1.3527323 2002  1.3527323
    15536 2.1388013  -2.633168 2002   2.633168
    15543 1.6265107  -.1318021 2002   .1318021
    15550  1.585621 -1.1615623 2002  1.1615623
    15557 2.0878482  -.6251392 2002   .6251392
    15564 2.0168262  -1.122699 2002   1.122699
    15571 1.4484754   .5845769 2002   .5845769
    15578 1.7805477  1.5606302 2002  1.5606302
    15585  1.525958  .02931488 2002  .02931488
    15592 2.3180652  -2.799415 2002   2.799415
    15599 1.6707025 -1.6376716 2002  1.6376716
    15606 2.5378354 .026403705 2002 .026403705
    15613 1.6017348 -1.8123453 2002  1.8123453
    15620         0          0 2002          0
    15627 2.2233071  -3.020985 2002   3.020985
    15634  2.758704  -.4821299 2002   .4821299
    15641 2.2093017 -1.8539804 2002  1.8539804
    15648 2.1681485  2.1972647 2002  2.1972647
    15655 1.6749827  -2.788559 2002   2.788559
    15662  3.588643  -4.780155 2002   4.780155
    15669  3.346243  -4.567672 2002   4.567672
    15676 1.8651558  .03562433 2002  .03562433
    15683 2.2610478   .4898008 2002   .4898008
    15690 1.6952885  1.0478189 2002  1.0478189
    15697  1.901793  1.8837024 2002  1.8837024
    15704  3.395599  -4.671672 2002   4.671672
    15711  2.772347 -1.2277025 2003  1.2277025
    15718 2.1912358   3.483433 2003   3.483433
    15725  3.687262   5.716919 2003   5.716919
    15732 2.4519944   .3525168 2003   .3525168
    15739  .9451538  .14199395 2003  .14199395
    15746 1.2781053  -.9503823 2003   .9503823
    15753 1.6940317   1.431836 2003   1.431836
    15760 2.2230365 -1.1358991 2003  1.1358991
    15767 1.9164674  2.3592293 2003  2.3592293
    15774 2.4346666  -3.939136 2003   3.939136
    15781 2.6690204  .04388403 2003  .04388403
    15788  1.442735 .012047686 2003 .012047686
    15795 1.8391362   1.584176 2003   1.584176
    15802 2.3038082  -.3085499 2003   .3085499
    15809  4.650578    4.98953 2003    4.98953
    15816  2.918732  -1.697974 2003   1.697974
    15823 4.6705866   -2.76868 2003    2.76868
    15830  3.494127 -1.6048017 2003  1.6048017
    15837  2.977946 -.01338571 2003  .01338571
    15844 3.3964925   2.671273 2003   2.671273
    15851  3.643645    1.46425 2003    1.46425
    15858  4.041341   1.270017 2003   1.270017
    15865  2.878992  -4.592948 2003   4.592948
    15872 2.8937554  1.9754747 2003  1.9754747
    15879 1.9556812 -3.3694615 2003  3.3694615
    15886 3.5537255 -2.2777672 2003  2.2777672
    15893  2.549982   .6448685 2003   .6448685
    15900 2.0797458   1.192847 2003   1.192847
    15907  3.549946 -2.6754115 2003  2.6754115
    15914 2.1864173 -1.5634494 2003  1.5634494
    15921 1.9790592   2.047979 2003   2.047979
    15928  1.656871  -.9543859 2003   .9543859
    15935  1.760976 -1.5156193 2003  1.5156193
    15942  2.576479  -1.520167 2003   1.520167
    15949 2.3478339  1.9608448 2003  1.9608448
    15956 2.1813831  -1.797851 2003   1.797851
    15963 2.5223765  -2.324635 2003   2.324635
    15970 2.0894804 -.58425045 2003  .58425045
    15977 2.3127463  -2.599389 2003   2.599389
    15984  .8075221   .8873354 2003   .8873354
    15991  1.284165    2.47579 2003    2.47579
    15998 1.6533177   -3.03647 2003    3.03647
    16005  3.750155  -.2284442 2003   .2284442
    16012  4.875941 -1.5789025 2003  1.5789025
    16019  4.833535  -2.918827 2003   2.918827
    16026 2.1364899  -.8974869 2003   .8974869
    16033 3.2972984     4.7895 2003     4.7895
    16040  2.786816   1.797363 2003   1.797363
    end
    format %td date
    I then tried to do it with other lags specification, unfortunately, the same problem persists:
    Code:
    . newey  csad c.abs_r_mt##c.abs_r_mt, lag(2)
    date is regularly spaced, but does not have intervals of 1
    r(198);
    
    .
    I have tried searching the error phrases both on Google and Statalist, I have come across NOTHING at all, does it mean that my case is extremely rare? Most importantly, what actually went wrong?


  • #2
    If the trading days are consecutive and there are no holes, you may consider the first date as time1, the second as time2, and so on. Therefore

    Code:
    sort date
    gen time=_n
    tsset time
    newey  csad c.abs_r_mt##c.abs_r_mt, lag(1)
    If these are random returns taken at different points in time, then you should think a little bit more about what you are trying to do.

    Comment


    • #3
      You have daily dates, but just a single weekly observation for the Monday in each week. Your tsset for this data was not specified appropriately.

      Notice the difference in what tsset reports with the command you probably used, and with the correct version for your sample data.
      Code:
      . tsset date
              time variable:  date, 07jan2002 to 01dec2003, but with gaps
                      delta:  1 day
      
      . tsset date, delta(7 days)
              time variable:  date, 07jan2002 to 01dec2003
                      delta:  7 days
      In general, gaps in time series data are Not a Good Thing.

      Comment


      • #4
        Dear William and Musau,

        Thanks for your inputs. I have, as suggested by William, changed my tsset specification. Another question arises, and you will see it below:

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input int date float(csad r_mt abs_r_mt)
        15341         .          .         .
        15372  8.436224 -12.511042 12.511042
        15400 3.3225675  1.9648436 1.9648436
        15431  7.411424   9.583619  9.583619
        15461  5.605823  3.4607785 3.4607785
        15492  5.201907  -10.41467  10.41467
        15522  6.498603   13.83425  13.83425
        15553 4.1513767 -3.1880274 3.1880274
        15584   2.72628  1.0409108 1.0409108
        15614 4.0416083  -6.223028  6.223028
        15645  5.389867 -4.6561255 4.6561255
        15675  6.631547 -10.604467 10.604467
        15706 4.3471274 -2.0230613 2.0230613
        15737  6.163964   9.239872  9.239872
        15765  3.007635   1.704784  1.704784
        15796  3.893607  -1.587202  1.587202
        15826  12.98457 -2.1023018 2.1023018
        15857  5.347927   5.392154  5.392154
        15887  4.101147  -8.716791  8.716791
        15918  5.460991 -1.1276236 1.1276236
        15949  4.401002   -.802781   .802781
        15979  4.695461   -6.41879   6.41879
        16010  8.431628 -2.3680263 2.3680263
        16040  4.248314    2.77055   2.77055
        16071  7.948152 -.08662705 .08662705
        16102  5.976416   8.824282  8.824282
        16131  7.156741  8.5455265 8.5455265
        16162  6.598279   2.931958  2.931958
        16192  6.662524 -12.454858 12.454858
        16223  4.943614 -.13449205 .13449205
        16253  5.744555 -11.035892 11.035892
        16284  7.770133  -4.800909  4.800909
        16315  5.599969  -5.720576  5.720576
        16345  6.091397   7.662899  7.662899
        16376  8.607979   -6.84691   6.84691
        16406  6.134023    2.50735   2.50735
        16437  7.697844     -7.467     7.467
        16468  8.073707   -7.12877   7.12877
        16496 4.2788343  10.215192 10.215192
        16527  6.864724  -6.697318  6.697318
        16557 10.891788  -8.308406  8.308406
        16588  8.302193 -10.174953 10.174953
        16618  6.594253  -1.306629  1.306629
        16649  8.303922  1.3506366 1.3506366
        16680   11.2914  11.181755 11.181755
        16710  6.459751 -1.1536884 1.1536884
        16741  7.689352   -5.73104   5.73104
        16771  6.338261   .6175821  .6175821
        16802 4.3295684   4.632648  4.632648
        16833 9.1836815   8.995499  8.995499
        16861  6.077281   3.366835  3.366835
        16892  9.024069  3.6101246 3.6101246
        16922 13.108974   7.246772  7.246772
        16953 12.284817   19.91872  19.91872
        16983  8.959021   2.630195  2.630195
        17014  9.179778  -9.174119  9.174119
        17045  7.507405   3.316923  3.316923
        17075  5.662868   5.209397  5.209397
        17106  6.947441  2.1305964 2.1305964
        17136 10.264326  10.832777 10.832777
        17167  9.773865   9.396377  9.396377
        17198  9.617068  18.595917 18.595917
        17226  11.13708   8.833343  8.833343
        17257  9.992418  16.287004 16.287004
        17287  12.05036   23.37832  23.37832
        17318 15.995577   5.864699  5.864699
        17348  19.03857 -4.5951257 4.5951257
        17379  10.58591   13.97101  13.97101
        17410 12.910087    18.6199   18.6199
        17440  9.278922   2.939992  2.939992
        17471 11.715993  -7.272669  7.272669
        17501  10.56437   -13.4348   13.4348
        17532  5.599703   15.03479  15.03479
        17563  9.197095 -12.709573 12.709573
        17592  6.502603  10.337528 10.337528
        17623  11.54764 -32.929096 32.929096
        17653  9.982803   7.562576  7.562576
        17684  7.970956  -5.452303  5.452303
        17714 11.655103  -29.46325  29.46325
        17745  9.313706   7.531732  7.531732
        17776 10.240597  -27.24382  27.24382
        17806  9.038309  -3.427655  3.427655
        17837 13.412267  -27.49006  27.49006
        17867  8.933171  17.450539 17.450539
        17898  7.807279  -.3152318  .3152318
        17929  7.190331  11.987215 11.987215
        17957  8.212899   7.716379  7.716379
        17988   8.45233  17.186045 17.186045
        18018  7.430564   3.718705  3.718705
        18049  6.803858    8.14052   8.14052
        18079   8.82491   8.066118  8.066118
        18110  9.652463   15.51348  15.51348
        18141  7.239003 -23.743225 23.743225
        18171   8.52014   5.252904  5.252904
        18202  6.789934  13.509326 13.509326
        18232 12.144785  11.025484 11.025484
        18263  5.653536   -.949526   .949526
        18294  7.025649  -8.584202  8.584202
        18322  5.034777   7.229745  7.229745
        18353  8.442362   3.608491  3.608491
        18383  9.804841   -9.97802   9.97802
        18414  7.413955  -9.025985  9.025985
        18444  6.932698  -8.916621  8.916621
        18475  5.629972  16.368925 16.368925
        18506  6.990912   4.834938  4.834938
        18536  6.541029   1.402888  1.402888
        18567  10.63143  13.805274 13.805274
        18597  8.259201   -2.79766   2.79766
        18628  5.767099 -1.0636408 1.0636408
        end
        format %td date
        I have a monthly data now, and I have specified it as
        Code:
        tsset date, delta(28 days)
                time variable:  date, 01jan2002 to 01jan2011, but with gaps
                        delta:  28 days
        ,

        I do not see where did the gaps come from. If Stata was referring to the first row that had dashes in it, it is due to the nature of the regression specification- we subtract stock prices at time t-1 from stock prices at time t, i.e. today's price minus yesterday's price, to find the price difference, hence, we would end up having 1 less observation. Why, to Stata at least, is that classified as a gap, which William deem highly unfavourable?

        Comment


        • #5
          You don't have regular observations at exactly 28 day intervals here. In fact only 7 of your observations are precisely 28 days after the preceding one. To see this:

          Code:
          sort date
          gen gap = date - date[_n-1]
          tab gap
          If your data are supposed to be at regular 28 day intervals, then something has gone wrong in the creation of this data set, and that needs to be revisited and fixed. If your expectation that it would have regular 28 day intervals is wrong, then you may need to rethink your plans for this data. It will be suitable for some purposes, but not for any that require equally spaced observations.

          Comment


          • #6
            A few seconds' work looking at your dates shows that they are monthly dates given as the first day of each month. That explains simply why they aren't a fixed number of days apart.

            Code:
            clear
            input int date 
            15341  
            15372  
            15400 
            15431 
            15461 
            15492 
            15522 
            end 
            
            format date %td
            
            list, sep(0)
            
                 +-----------+
                 |      date |
                 |-----------|
              1. | 01jan2002 |
              2. | 01feb2002 |
              3. | 01mar2002 |
              4. | 01apr2002 |
              5. | 01may2002 |
              6. | 01jun2002 |
              7. | 01jul2002 |
                 +-----------+
            The remedy is to work with equivalent monthly dates with something like

            Code:
            gen mdate = mofd(date) 
            format mdate %tm
            tsset mdate
            It's important to be familiar with your data in detail before you get into any attempt at modelling.

            Comment


            • #7
              Let me add that the problem posed in post #4 is essentially the same as the problem posed earlier at

              https://www.statalist.org/forums/for...-in-newey-west

              which apparently you did not see my answer to. I will repeat the advice I gave there.

              Stata's "datetime" variables are complicated and there is a lot to learn. As you learned in this topic, there is a difference between "monthly" dates and "daily dates chosen one per month." There is much else for you to learn.

              As you apparently have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. Everyone should do so before attempting to work with Stata dates and times.

              After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

              All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

              Comment


              • #8
                Dear Clyde, Nick and William,

                Thanks for your (very) valuable inputs, I have dealt with it successfully.

                Comment

                Working...
                X