Announcement

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

  • #16
    Your data are declared as daily data, but they are really monthly data indexed by some day late in each month. So, there is no good solution until that nettle is grasped.

    Please use dataex (SSC) for your examples as requested in the FAQ Advice (that would have made some minor surgery below unnecessary).


    Code:
    clear 
    input str9 sdate str1 ticker vwretd movage2
    31jan1975 A .1415997 0
    28feb1975 A .05841149 0
    31mar1975 A .03019056 0
    30apr1975 A .04649668 0
    30may1975 A .05513976 0
    30jun1975 A .05147306 0
    31jul1975 A -.06038489 0
    29aug1975 A -.02355698 0
    30sep1975 B -.03801003 0
    31oct1975 B .05585698 0
    28nov1975 B .03122338 0
    31dec1975 B -.01099793 0
    30jan1976 B .1260112 0
    27feb1976 B .00731444 0
    31mar1976 B .02679926 0
    30apr1976 B -.01038881 0
    28may1976 B -.00936875 0
    30jun1976 B .04448723 0
    30jul1976 C -.00615711 0
    31aug1976 C -.00143513 0
    30sep1976 C .02448419 0
    29oct1976 C -.02037277 0
    30nov1976 C .00536438 0
    31dec1976 C .06159097 0
    31jan1977 C -.03633707 0
    31aug1978 C .04235237 0
    29sep1978 C -.0068907 0
    31oct1978 C -.1109973 0
    30nov1978 D .03379215 0
    29dec1978 D .01771047 0
    31jan1979 D .04948888 0
    28feb1979 D -.02676587 0
    30mar1979 D .0656175 0
    30apr1979 D .008522 0
    31may1979 D -.01357596 0
    29jun1979 D .04685007 0
    31jul1979 D .01499138 0
    31aug1979 D .06472839 0
    28sep1979 D .00142826 0
    31oct1979 D -.07265966 0
    end 
    
    gen date = daily(sdate, "DMY") 
    format date %td 
    
    gen mdate = mofd(date) 
    format mdate %tm 
    
    encode ticker, gen(tick) 
    xtset tick mdate 
    
    tsegen mean = rowmean(L(0/3).vwretd) 
    
    list date mdate tick vwretd mean, sepby(tick) 
    
         +----------------------------------------------------+
         |      date     mdate   tick      vwretd        mean |
         |----------------------------------------------------|
      1. | 31jan1975    1975m1      A    .1415997    .1415997 |
      2. | 28feb1975    1975m2      A    .0584115    .1000056 |
      3. | 31mar1975    1975m3      A    .0301906    .0767339 |
      4. | 30apr1975    1975m4      A    .0464967    .0691746 |
      5. | 30may1975    1975m5      A    .0551398    .0475596 |
      6. | 30jun1975    1975m6      A    .0514731     .045825 |
      7. | 31jul1975    1975m7      A   -.0603849    .0231812 |
      8. | 29aug1975    1975m8      A    -.023557    .0056677 |
         |----------------------------------------------------|
      9. | 30sep1975    1975m9      B     -.03801     -.03801 |
     10. | 31oct1975   1975m10      B     .055857    .0089235 |
     11. | 28nov1975   1975m11      B    .0312234    .0163568 |
     12. | 31dec1975   1975m12      B   -.0109979    .0095181 |
     13. | 30jan1976    1976m1      B    .1260112    .0505234 |
     14. | 27feb1976    1976m2      B    .0073144    .0383878 |
     15. | 31mar1976    1976m3      B    .0267993    .0372817 |
     16. | 30apr1976    1976m4      B   -.0103888     .037434 |
     17. | 28may1976    1976m5      B   -.0093688     .003589 |
     18. | 30jun1976    1976m6      B    .0444872    .0128822 |
         |----------------------------------------------------|
     19. | 30jul1976    1976m7      C   -.0061571   -.0061571 |
     20. | 31aug1976    1976m8      C   -.0014351   -.0037961 |
     21. | 30sep1976    1976m9      C    .0244842    .0056306 |
     22. | 29oct1976   1976m10      C   -.0203728   -.0008702 |
     23. | 30nov1976   1976m11      C    .0053644    .0020102 |
     24. | 31dec1976   1976m12      C     .061591    .0177667 |
     25. | 31jan1977    1977m1      C   -.0363371    .0025614 |
     26. | 31aug1978    1978m8      C    .0423524    .0423524 |
     27. | 29sep1978    1978m9      C   -.0068907    .0177308 |
     28. | 31oct1978   1978m10      C   -.1109973   -.0251785 |
         |----------------------------------------------------|
     29. | 30nov1978   1978m11      D    .0337921    .0337921 |
     30. | 29dec1978   1978m12      D    .0177105    .0257513 |
     31. | 31jan1979    1979m1      D    .0494889    .0336638 |
     32. | 28feb1979    1979m2      D   -.0267659    .0185564 |
     33. | 30mar1979    1979m3      D    .0656175    .0265127 |
     34. | 30apr1979    1979m4      D     .008522    .0242156 |
     35. | 31may1979    1979m5      D    -.013576    .0084494 |
     36. | 29jun1979    1979m6      D    .0468501    .0268534 |
     37. | 31jul1979    1979m7      D    .0149914    .0141969 |
     38. | 31aug1979    1979m8      D    .0647284    .0282485 |
     39. | 28sep1979    1979m9      D    .0014283    .0319995 |
     40. | 31oct1979   1979m10      D   -.0726597    .0021221 |
         +----------------------------------------------------+

    Comment


    • #17
      Sorry I got where I made the mistake. It is the date which is given monthly but because I didn't specify so Stata is considering it daily

      Comment


      • #18
        Thank you so much Nick once again for your quick response

        Comment


        • #19
          The wording of #17 does not match the problem. The dates you started with are daily. It's only people who can look and see that they define monthly data. Stata can only see time series that are mostly gaps. That's why a monthly date must be constructed.

          Comment


          • #20
            I apologize for wording incorrectly #17. I have another query. The date is given in the following string (type str9)
            31-Dec-75
            31-Jan-86

            To convert this to monthly I used both daily and date function however the command generates missing values for all the observations.

            Comment


            • #21
              This is really a different question, but I'll answer it here rather than insist on a new thread.

              What I asked in #16 still holds.

              Please use dataex (SSC) for your examples as requested in the FAQ Advice (that would have made some minor surgery below unnecessary).
              Try this:

              Code:
              clear 
              input str9 givendate 
              "31-Dec-75" 
              "31-Jan-86"
              end 
              
              gen wanteddate = mofd(daily(givendate, "DMY", 2050)) 
              format wanteddate %tm 
              
              list 
              
              help datetime
              Everything you need here is documented in the help just referenced. What distinguishes people who know how to do this is that they read the documentation!


              Comment

              Working...
              X