Announcement

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

  • t-test of a variable on its lag in panel data

    Hi,
    I need to run a t-test of volume variable in the following dataset on its lag having the same ticker value. I have defined n similar to following table as my timevar.
    How could I run a test like ttest volume==l2.volume, while keeping the ticker code constant. In other word, I need to test whether the volume of each ticker is different from the lagged volume of the same ticker.
    n ticker volume
    1 aapl 10
    2 aapl 20
    3 aapl 15
    1 spx 25
    2 spx 23
    3 spx 15
    1 ibm 10
    2 ibm 15
    3 ibm 20
    I appreciate your suggestions.

  • #2
    Code:
    xtset ticker n
    by ticker (n), sort: ttest volume = L2.volume
    The use of the -by- prefix is bread and butter Stata. Do read the basic commands in the [GS] and [U] sections of the PDF manuals that come with your Stata installation.

    I should add that it strikes me that the use of a t-test for this purpose is inappropriate, but the above is how you would do it.

    Comment


    • #3
      Hi Clyde Schechter ,

      Somehow similar question. I want to run t-test for lagged variable so I run this code and get the below error message:

      ttest l.score, by(indicator)
      factor-variable and time-series operators not allowed
      r(101);

      Would I advise me, please? Can I do anything to perform a t-test for that lagged variable?

      Thanks in advance.

      Comment


      • #4
        The -ttest- command does not allow time-series operators. You have to create a separate variable for this.

        Code:
        gen lag_score = l.score
        ttest lag_score, by(indicator)
        Or, you can do this by regression instead of using -ttest-, in which case you can use the lag operator:

        Code:
        regress l.score i.indicator
        These will give the same results.

        Comment


        • #5
          Many thanks Clyde for this suggestions.

          Comment


          • #6
            Hi Clyde Schechter

            As you suggested the 't-test for this purpose is inappropriate' could you explain why the default STATA version of such a test would not be valid? What would be an appropriate way to test the coefficient on a lagged variable?

            Comment


            • #7
              When you have repeated observations on the same entities (firms, people, securities, whatever), the observations within a given entity are usually correlated with each other. Moreover,
              what is x in a given observation becomes L.x in the next observation, further increasing the correlation between successive observations in this context. When you do a t-test (whether using Stata software or any other) one of the key assumptions underlying it is that the observations are all independent, but, as just explained, that is not true with longitudinal data.

              As for what is a reasonable substitute, I really don't know. This kind of question does not arise in my line of work. There are other Forum members who work in time series analysis frequently, and I hope one of them has a suggestion for you.

              Comment

              Working...
              X