Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: AW: xttab for 2-way tables


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: AW: xttab for 2-way tables
Date   Tue, 04 Aug 2009 09:13:30 -0500

I am not clear what precisely you seek. This example may or may not help. The idea is to work with a composite variable formed by -egen-'s -group()- function. If it helps, a bonus is that it can be applied to two or more variables.

Nick

. webuse nlswork
(National Longitudinal Survey.  Young Women 14-26 years of age in 1968)

. xtset id year
       panel variable:  idcode (unbalanced)
        time variable:  year, 68 to 88, but with gaps
                delta:  1 unit

. xttab msp

                  Overall             Between            Within
      msp |    Freq.  Percent      Freq.  Percent        Percent
----------+-----------------------------------------------------
        0 |   11324     39.71      3113     66.08          62.69
        1 |   17194     60.29      3643     77.33          75.75
----------+-----------------------------------------------------
    Total |   28518    100.00      6756    143.41          69.73
                              (n = 4711)

. xttab race

                  Overall             Between            Within
     race |    Freq.  Percent      Freq.  Percent        Percent
----------+-----------------------------------------------------
        1 |   20180     70.72      3329     70.66         100.00
        2 |    8051     28.22      1325     28.13         100.00
        3 |     303      1.06        57      1.21         100.00
----------+-----------------------------------------------------
    Total |   28534    100.00      4711    100.00         100.00
                              (n = 4711)

. egen both = group(msp race), label
(16 missing values generated)

. xttab both

                  Overall             Between            Within
     both |    Freq.  Percent      Freq.  Percent        Percent
----------+-----------------------------------------------------
      0 1 |    6853     24.03      2046     43.43          57.56
      0 2 |    4359     15.29      1036     21.99          72.65
      0 3 |     112      0.39        31      0.66          68.24
      1 1 |   13321     46.71      2747     58.31          78.32
      1 2 |    3682     12.91       853     18.11          67.09
      1 3 |     191      0.67        43      0.91          83.36
----------+-----------------------------------------------------
    Total |   28518    100.00      6756    143.41          69.73
                              (n = 4711)

Thomas Klausch wrote:
Thanks Martin, this kinda works. However it is still a bit of a
nuissance. I take that there is no direct command such as xttab, but
just made for 2-way tables?



2009/8/3 Martin Weiss <[email protected]>:

Why not -collapse- the thing beforehand? If the characteristics are
time-invariant, nothing gets lost this way. Then use -tab- as in


*************
help tabulate twoway
*************

with all the tests available...

Thomas Klausch

I am trying to produce a 2 way table for time invariant
characteristics in panel data. For a one way table this can be done
using xttab as I understand. However is there a command for producing
a 2 way contingency table alongside suitable tests? Or do I need to
agregate data to the macro level before I can do this (which would be
inconvenient I suppose)?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index