Announcement

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

  • Breaking down variables by multiple other variables

    I have already broken down two variables (sat and colgpa) by whether or not the student is an athlete or not. However, I am trying to further break down the analysis by gender. That is, I would like to report the same statistics by athlete status separately for both genders. I have successfully done this using two separate tables; however, am wondering if it is possible to accomplish this in one table.


    Here is my first table, breaking down the two variables by athlete status.
    Click image for larger version

Name:	tabstat1.png
Views:	1
Size:	6.9 KB
ID:	1433291


    Here are my two tables (one for male, one for female) breaking down the two variables by athlete status.
    Click image for larger version

Name:	tabstat2.png
Views:	1
Size:	16.1 KB
ID:	1433292


    What I cannot figure out is whether there is a way to condense these two tables down into one table, as the two tables are not as visually descriptive.

  • #2
    The layout will not be quite the same, but you can do this with the -table- command:
    Code:
    table athlete female, c(mean sat sd sat mean colgpa sd colgpa)

    Comment


    • #3
      A simple strategy is just to create your summary variables first and then reach for a basic "show me" command. Here I have echoed your example of mean and SD for two numeric variables for a cross-combination of binary variables, but the strategy is much more general.

      I use a dataset all can use; conversely using your own data and showing results as images isn't the best way to give examples for us to answer. Please do read and act on FAQ Advice #12.


      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      .
      . gen himpg = mpg > 30
      
      .
      . foreach s in mean sd {
        2.    foreach v in weight price {
        3.        egen `v'_`s' = `s'(`v'), by(foreign himpg)
        4.            label var `v'_`s' "`s' `v'"
        5.            format `v'_`s' %2.1f
        6.     }
        7. }
      (1 missing value generated)
      (1 missing value generated)
      
      .
      . egen group = group(foreign himpg), label
      
      . tab group
      
      group(forei |
        gn himpg) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
       Domestic 0 |         51       68.92       68.92
       Domestic 1 |          1        1.35       70.27
        Foreign 0 |         18       24.32       94.59
        Foreign 1 |          4        5.41      100.00
      ------------+-----------------------------------
            Total |         74      100.00
      
      . label def group 1 "Domestic Low" 2 "Domestic High" 3 "Foreign Low" 4 "Foreign High",
      >  replace
      
      .
      . tabdisp group, c(weight_* price_*)
      
      ------------------------------------------------------------------
      group(foreign |
      himpg)        | mean weight    sd weight   mean price     sd price
      --------------+---------------------------------------------------
       Domestic Low |      3346.9        668.0       6104.7       3119.1
      Domestic High |      1800.0                    4425.0            
        Foreign Low |      2368.9        462.7       6829.5       2689.4
       Foreign High |      2077.5         82.6       4383.0        778.0
      ------------------------------------------------------------------
      
      .
      . * groups should be installed from Stata Journal website
      . groups group weight_* price_*, show(f) missing
      
        +-------------------------------------------------------------------+
        |         group   weight~n   weight~d   price_~n   price_sd   Freq. |
        |-------------------------------------------------------------------|
        |  Domestic Low     3346.9      668.0     6104.7     3119.1      51 |
        | Domestic High     1800.0          .     4425.0          .       1 |
        |   Foreign Low     2368.9      462.7     6829.5     2689.4      18 |
        |  Foreign High     2077.5       82.6     4383.0      778.0       4 |
        +-------------------------------------------------------------------+
      
      .  
      . groups group weight_* price_*, show(f) missing colorder(1 6)
      
        +-------------------------------------------------------------------+
        |         group   Freq.   weight~n   weight~d   price_~n   price_sd |
        |-------------------------------------------------------------------|
        |  Domestic Low      51     3346.9      668.0     6104.7     3119.1 |
        | Domestic High       1     1800.0          .     4425.0          . |
        |   Foreign Low      18     2368.9      462.7     6829.5     2689.4 |
        |  Foreign High       4     2077.5       82.6     4383.0      778.0 |
        +-------------------------------------------------------------------+
      PS Graphs are good too.

      On groups see

      SJ-17-3 st0496 . . . . . Speaking Stata: Tables as lists: The groups command
      (help groups if installed) . . . . . . . . . . . . . . . . N. J. Cox
      Q3/17 SJ 17(3):760--773
      presents command for listing group frequencies and percents and
      cumulations thereof; for various subsetting and ordering by
      frequencies, percents, and so on; for reordering of columns;
      and for saving tabulated data to new datasets

      or https://www.statalist.org/forums/for...updated-on-ssc

      Comment

      Working...
      X