Announcement

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

  • within-group covariance by year

    Hi there,
    I would like to compute the within-firm covariance(wage_t, wage_{t-1}) for each year. I listed some sample panel data below.

    year firm job wage
    2000 1 1 10
    2000 1 2 11
    2000 1 3 10
    2000 2 4 8
    2000 2 5 4
    2000 2 6 11
    2000 2 7 5
    2000 3 8 5
    2000 3 9 9
    2000 4 10 7
    2000 4 11 8
    2001 1 1 10.5
    ...
    ...

    If it were not covariance, I could have just used egen ... by (year firm) to generate a wage moment for each firm each year and then take the mean across firms to get one number for each year to compute the average within-firm wage moment for each year. With tabstat I could easy print the within-firm moment by year as a table. But egen does not go with corr command.

    But since I need covariance, so far I tried bysort firm year: cor wage lagwage, covariance, it gives me a matrix for each firm-year pair, but then I will have to manually select the covariance I need from a matrix in each firm-year pair and then compute the average cov across firms for each year. There are too many firms and year, and thus their pairs in the real data to make this an efficient approach. Any better solutions that allow me to calculate and print the results out by year as a table?

    Thanks!

  • #2
    You can't compute covariance(wage_t, wage_{t-1}) with this data, because wage_{t-1} isn't defined. That's because for each firm you have multiple values of wage in each year. So, consider firm 1 year 2001. What is the value for wage in firm 1 year 200. Is it 10, or 11? There is no way to know. Either you are not correctly describing the calculation you want, or your data are incompatible with it.

    Comment


    • #3
      Cross-posted at https://stackoverflow.com/questions/...riance-by-year Please note our policy on cross-posting, which is that you are asked to tell us about it. This is explained in the FAQ Advice all members are asked to read before posting,

      Comment


      • #4
        To answer Clyde's question, it is to calculate covariance(wage_firm_job_t, wage_firm_job_{t-1}) for the same firm's same job over time. But I would like to compute within-firm's covariance first, i.e., for each firm, I compute its jobs' covariance between t and t-1, and then take the mean across firms of the within-firm covariances for each year. Hope this clarifies.

        Comment


        • #5
          Never mind, I figured it out by myself. It took stata overnight to produce all the output I needed. Stata should have egen for more moments, like covariance, not just current most basic statistics.

          Comment

          Working...
          X