Announcement

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

  • Mean, StDev, N, t-value in one command

    Hello Guys

    I have a dataset which shows the following:
    Firm date return DayofWeek
    AARGKB January 3, 2008 -0.001 4
    AARGKB January 4, 2008 -0.007 5
    AARGKB January 7, 2008 -0.013 1
    AARGKB January 8, 2008 -0.0121 2
    .....
    I have a dataset with over 200 different firms. Now i want to have this result:
    DayofWeek Mean St. Dev N t-value
    1
    2
    3
    4
    5
    So im trying to collapse the mean of every monday in one, the mean of every tuesday in one and this for every day of the week.
    Code:
    collapse (mean) adjretadd1, by(dayofweek)
    With this code i managed to get the mean, which i think is correct. But when i now try to get the other ones (StDev, N and t-value), i don't know how i can do it with one command.
    Code:
    correlate dailyreturns, means cov
    With this, i get then the mean of the 5 days in one, but that's not what i wanted. I also get only N of 5, which is also not correct (the problem is that i then take the results i get from my first command and calculate with them, but i want to calculate with the initial dataset). Is there a command with which i get the results i wanted at once?

    Thank you very much for every help.

    Best,
    Anthony

  • #2
    -collapse- is not restricted to calculating one statistic.

    Code:
    collapse (mean) Mean = adjretadd1 (sd) Std_Dev = adjretadd1 (count) N = adjretadd1, by(dayofweek)
    That will get you everything but "t-value" in one command. I'm not sure I grasp what kind of "t-value" you are looking for here. If you mean a t-statistic for the hypothesis that Mean = 0, you can calculate that easily after the above with:
    Code:
    gen t_stat = Mean/(Std_Dev/sqrt(N))

    Comment


    • #3
      bysort DayofWeek: summarize return
      would give you everything but t-value
      if you want to get the t value of the coefficient estimate for the mean of returns you need to
      reg return i.DayofWeek
      those would be the t values to test if mean return by day of week is different than the mean of the left out category
      if you want the tvalue for the test if the mean is different from 0 then you can do

      reg return i.DayofWeek, noconstant

      Comment


      • #4
        Hello Clyde and Oscar

        Thank you very much, both ways worked and you helped me a lot!
        I have one question remaining; If i do either our your ways, i get for N a value of 364 for every day (only a sample, not the whole data). Is this N the number of Mondays/Tuesdays..../Fridays i have in my data?

        Comment


        • #5
          Yes each N would be the number of data points from which the stats are calculated for each day. If you had data missing for one Friday lets say N would be one less than the other Ns for the Friday stats.

          Comment


          • #6
            Originally posted by Anthony Kira View Post
            Hello Clyde and Oscar

            Thank you very much, both ways worked and you helped me a lot!
            I have one question remaining; If i do either our your ways, i get for N a value of 364 for every day (only a sample, not the whole data). Is this N the number of Mondays/Tuesdays..../Fridays i have in my data?
            To be more specific: Lets say i take the return of a firm for 10 years. So i have approx. 500 mondays for this firm. Only in 400 Mondays i have actually a return, in the other 100 mondays the firm was not listed or illiquid (return empty).
            The N should be 400 and not 500. Does the command from Clyde or Oscar take this into account?


            UPDATE: My post crossed with Oscar's.
            Thank you very much Oscar and Clyde!

            Comment


            • #7
              Yes if return is missing for a specific day, that day is not included in as an observation. So, N you would see would correspond to 400 in your example in either approach.

              Comment

              Working...
              X