Export xtsum from Stata to Excel, Word


xtsum, a generalization of summarize, reports means and standard deviations for panel data; it differs from summarize in that it decomposes the standard deviation into between and within components. Exporting its table is as easy as adding asdocx to the beginning of the command. A panel variable must be specified; use xtset. varlist may contain time-series operators;

 

See the following examples.

 * Load example data
 webuse nlswork
 
  * Default case
 asdocx xtsum race grade , replace
 
Table: Results
Variable Mean Std. Dev. Min Max Observations
race overall 1.303 0.482 1 3 N = 28534
between 0.486 1 3 n = 4711
within 0 1.303 1.303 T-bar = 6.057
grade overall 12.533 2.324 0 18 N = 28532
between 2.567 0 18 n = 4709
within 0 12.533 12.533 T-bar = 6.059
Notes:
  * Use labels
 asdocx xtsum race grade , replace label
Table: Results
Variable Mean Std. Dev. Min Max Observations
Race overall 1.303 0.482 1 3 N = 28534
between 0.486 1 3 n = 4711
within 0 1.303 1.303 T-bar = 6.057
Current grade completed overall 12.533 2.324 0 18 N = 28532
between 2.567 0 18 n = 4709
within 0 12.533 12.533 T-bar = 6.059
Notes:
  * Two decimal points
 asdocx xtsum race grade , replace label dec(2)
Table: Results
Variable Mean Std. Dev. Min Max Observations
Race overall 1.3 0.48 1 3 N = 28534
between 0.49 1 3 n = 4711
within 0 1.3 1.3 T-bar = 6.06
Current grade completed overall 12.53 2.32 0 18 N = 28532
between 2.57 0 18 n = 4709
within 0 12.53 12.53 T-bar = 6.06
Notes:

  Explanation of the xtsum table


The following example is taken from the Stata manual. If you have not read xt, please do so. xtsum provides an alternative to summarize. For instance, in the nlswork dataset described in [XT] xt, hours contains the usual hours worked:


. use https://www.stata-press.com/data/r18/nlswork

summarize hours

Variable     | Obs    Mean     Std. dev. Min M ax
-------------+-----------------------------------------
hours        | 28,467 36.55956 9.869623  1    168

* use xtsum

xtsum hours

 

        Variable | Mean    Std. dev.          Min       Max      Observations
   --------------+----------------------------------------------+----------------
   hours overall | 36.55956 9.869623            1       168     | N = 28467
         between |          7.846585            1      83.5     | n = 4710
          within |          7.520712    -2.154726  130.0596     | T-bar = 6.04395
   --------------+----------------------------------------------+----------------

xtsum provides summary statistics on the variable  x_it . It breaks down  x_it  into:

– A between component ( \bar{x}_i ), which is the average for each person  i . This is calculated over 4,710 persons.

– A within component ( x_it –  \bar{x}_i  \bar{\bar{x}} ), which is the deviation of each observation from the person’s average plus the global average  \bar{\bar{x}} . This shows the variation within each person over time.

The data covers  28,467 person-years. On average each person was observed for  6 years.

xtsum also reports the minimums and maximums. Hours worked last week ranged from  1 to  168  . The average hours worked for each woman ranged from  1 to  83.5 .

The “within” hours varied from  -2.15 to  130.1 . This does not mean any woman worked negative hours, just that some deviations from personal averages were negative. The  130.1 value is also misleading – it reflects a deviation of  130.1 - 36.6 = 93.5 from one woman’s average.

An interesting finding is that the variation in hours worked across women is nearly equal to the variation within each woman over time. That is, the difference in hours between two random women is similar to the difference for one woman between two random years.

  Order asdocx


Yearly license of asdocx is available at $9.99. Its life-time license is available at $49.99. With the asdocx membership, you get :

  • Life-time license to use
  • All future updates
  • All premium templates / plugins.

 

Order asdocx