1
votes

I'm using the xt commands, including xtsum, to analyze panel data in Stata. I'm either misunderstanding the output for "T-bar", or I made a mistake in one of my variables.

My xtsum output looks like this:

Variable          Mean    Std. Dev.  Min        Max      Observations

hours  overall  43.83559  31.24379   1          160         N = 1215108
       between            25.89261   1          160         n =   44773
       within             19.69052  -92.83108   188.2023    T-bar = 27.1393

My understanding is that T-bar represents the average number of observations per panel variable (in this case, per person). However, I also have a variable set up that counts the number of observations per person:

sort hcw_id pp_id
egen ppcount = max(pp_id), by(hcw_id)

pp_id is an observation ID per person, and hcw_id is the person ID. I've checked in the Data Editor to verify that pp_id is counting observations per peson and ppcount is taking the max value of pp_id for each person. For example, if there are 10 records for a person, each record will be labeled 1-10 with pp_id and ppcount will be 10.

Here is the confusing thing: the mean of ppcount is 46. This should mean that people in the data have, on average, 46 observations. But why is this so different from T-bar in the xtsum output? Am I misunderstanding something in the documentation for xtsum or is my ppcount variable way off?

By the way, I just thought of another way of double-checking this - pp_id counts the number of pay roll records per person. Based on other variables, I know that each person has worked around a year and a half, which would be about 40 biweekly pay periods. This suggests that ppcount is accurate, and T-bar is measuring something different.

Is anyone familiar with xtsum and able to shed some light on this? Thank you!

1

1 Answers

1
votes

You don't show us the code you used to calculate the mean, but your mean of ppcount is most likley off because you are including each person in the average proportionally to how many pay periods he has. For example, if you have two observations, one with 2 periods and one with 6 periods, you want to calculate T-bar = (2 + 6)/2 = 4, but you are calculating (2 + 2 + 6 + 6 + 6 + 6 + 6 + 6)/8 = 5 with unconditional summarize.

Try (assuming pay periods are numbered starting with 1)

sum ppcount if pp_id = 1

Here is some code showing this problem:

. clear

. input id t

            id          t
  1. 1 1
  2. 1 2
  3. 2 1
  4. 2 2
  5. 2 3
  6. 2 4
  7. 2 5
  8. 2 6
  9. end

. set seed 10011979

. gen y = rnormal(id,1)

. list, sepby(id) noobs

  +--------------------+
  | id   t           y |
  |--------------------|
  |  1   1   -.0547995 |
  |  1   2    1.713224 |
  |--------------------|
  |  2   1     2.17048 |
  |  2   2    1.184764 |
  |  2   3    1.765206 |
  |  2   4    -.027979 |
  |  2   5    1.975493 |
  |  2   6    .6068434 |
  +--------------------+

. xtset id t
       panel variable:  id (unbalanced)
        time variable:  t, 1 to 6
                delta:  1 unit

. xtsum y

Variable         |      Mean   Std. Dev.       Min        Max |    Observations
-----------------+--------------------------------------------+----------------
y        overall |  1.166654    .890562  -.0547995    2.17048 |     N =       8
         between |             .3181431   .8292124   1.279135 |     n =       2
         within  |             .8658653  -.1404596      2.058 | T-bar =       4

. sort id t

. egen t_count = max(t), by(id)

. sum t_count

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
     t_count |          8           5     1.85164          2          6

. sum t_count if t==1

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
     t_count |          2           4    2.828427          2          6