Announcement

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

  • Problems to generate table of 4 way with percent for total o row?

    Dear
    I am doing cross tables for 4 variables, but I report in frequencies and what I am looking for is to report it in percentages

    Command:

    table edad_categorizado sexo1 grado_instruccion1, by(SES) contents(freq)

    My goal is to evaluate: by total or rows or columns.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double edad_categorizado long(sexo1 grado_instruccion1) float SES
    5 1 3 1
    5 2 3 1
    5 2 2 1
    1 2 3 1
    3 1 3 1
    1 1 4 1
    3 2 4 1
    4 2 3 1
    1 2 3 1
    1 1 3 1
    5 1 3 1
    3 2 4 1
    1 2 2 1
    4 2 3 1
    8 2 3 1
    4 2 4 1
    4 2 3 1
    1 2 4 1
    6 1 4 1
    6 2 3 1
    5 1 3 1
    4 2 3 1
    1 1 3 1
    3 2 4 1
    4 2 3 1
    3 2 3 1
    1 1 3 1
    3 1 3 1
    1 1 4 1
    3 1 4 1
    1 1 3 1
    3 2 3 1
    3 1 3 1
    5 2 3 1
    1 1 3 1
    1 1 4 1
    1 1 4 1
    3 2 4 1
    3 1 4 1
    3 2 3 1
    4 2 3 1
    3 1 3 1
    4 2 3 1
    3 1 3 1
    4 1 4 1
    3 2 3 1
    3 2 4 1
    5 1 3 1
    3 1 3 1
    5 1 3 1
    5 1 4 1
    3 1 4 1
    4 2 3 1
    3 2 3 1
    1 1 3 1
    3 2 4 1
    8 1 3 1
    5 2 3 1
    4 1 2 1
    3 1 3 1
    3 1 3 1
    3 2 4 1
    1 1 4 1
    3 2 3 1
    1 2 3 1
    4 2 4 1
    1 1 3 1
    4 2 4 1
    3 1 3 1
    5 2 2 1
    3 2 4 1
    4 2 3 1
    6 2 3 1
    7 2 4 1
    1 2 3 1
    3 2 3 1
    4 2 3 1
    6 2 3 1
    6 2 4 1
    6 2 3 1
    4 1 3 1
    3 2 4 1
    3 1 4 1
    3 1 4 1
    4 1 3 1
    6 1 3 1
    4 1 3 1
    1 2 3 1
    3 2 4 1
    4 1 3 1
    3 2 4 1
    1 1 3 1
    4 2 3 1
    1 1 3 1
    3 2 3 1
    3 1 4 1
    6 1 3 1
    4 1 3 1
    3 2 4 1
    4 2 4 1
    end
    label values edad_categorizado edad_cat
    label def edad_cat 1 "0-10 años", modify
    label def edad_cat 3 "21-30 años", modify
    label def edad_cat 4 "31-40 años", modify
    label def edad_cat 5 "41-50 años", modify
    label def edad_cat 6 "51-60 años", modify
    label def edad_cat 7 "61-70 años", modify
    label def edad_cat 8 "70 a más", modify
    label values sexo1 sexo1
    label def sexo1 1 "F", modify
    label def sexo1 2 "M", modify
    label values grado_instruccion1 grado_int_4
    label def grado_int_4 2 "Nivel Primaria", modify
    label def grado_int_4 3 "Nivel Secundaria", modify
    label def grado_int_4 4 " Nivel Superior", modify
    label values SES SES
    label def SES 1 "Alto", modify

  • #2
    If I understand you correctly, the user written program -tab3way- (available on SSC) may be of use here. Using the data you have provided, the following illustrates how the program can provide cell, row and column percentages, without frequencies. By default -tab3way- presents percentages with 2 decimal places but that can be modified. Also, by judicious use of the program's options you can display just about any combination of percentages and frequencies that you wish.

    Code:
    . bysort SES: tab3way edad_categorizado sexo1 grado_instruccion1, allpct nofreq
    
    ------------------------------------------------------------------------------------------------------------
    -> SES = Alto
    
    
    Table entries are cell, row and column percentages
    Missing categories ignored
    
    ---------------------------------------------------------------
               |            grado_instruccion1 and sexo1           
    edad_categ | - Nivel Prim -    - Nivel Secu -    -  Nivel Sup -
    orizado    |      F       M         F       M         F       M
    -----------+---------------------------------------------------
     0-10 años |           1.00      9.00    5.00      5.00    1.00
               |         100.00     64.29   35.71     83.33   16.67
               |          33.33     29.03   15.63     35.71    5.26
               |
     21-30 año |                     9.00    8.00      6.00   12.00
               |                    52.94   47.06     33.33   66.67
               |                    29.03   25.00     42.86   63.16
               |
     31-40 año |   1.00              5.00   11.00      1.00    4.00
               | 100.00             31.25   68.75     20.00   80.00
               | 100.00             16.13   34.38      7.14   21.05
               |
     41-50 año |           2.00      5.00    3.00      1.00        
               |         100.00     62.50   37.50    100.00        
               |          66.67     16.13    9.38      7.14        
               |
     51-60 año |                     2.00    4.00      1.00    1.00
               |                    33.33   66.67     50.00   50.00
               |                     6.45   12.50      7.14    5.26
               |
     61-70 año |                                               1.00
               |                                             100.00
               |                                               5.26
               |
      70 a más |                     1.00    1.00                  
               |                    50.00   50.00                  
               |                     3.23    3.13                  
    ---------------------------------------------------------------

    Comment

    Working...
    X