Announcement

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

  • Frequency tables for multi variables

    Hi,
    I am using stata 13, and I need to make a combined frequency table for many dependent variables, and one independent variable (they are all binary variables). It suppose to look like the following table (I have entered random numbers):
    Independent variable
    0 1
    V1 20% 10%
    V2 30% 50%
    V3 10% 20%
    V4 40% 20%
    total 100% 100%
    I am quite stuck with this, since tab is only for 2 variables, I hope you might have the answer.

    Thanks,
    Vered

  • #2
    You may use - tab1 - for that matter and incude several variables at once.

    Please look at the example below:

    Code:
    . tab1 foreign rep78
    
    -> tabulation of foreign  
    
       Car type |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |         52       70.27       70.27
        Foreign |         22       29.73      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    -> tabulation of rep78  
    
         Repair |
    Record 1978 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |          2        2.90        2.90
              2 |          8       11.59       14.49
              3 |         30       43.48       57.97
              4 |         18       26.09       84.06
              5 |         11       15.94      100.00
    ------------+-----------------------------------
          Total |         69      100.00
    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Adding a setting of variables. For this, use the option - firstonly - in the tab2 command:


      Code:
      . gen highwgt = weight > 3000
      
      . tab2 foreign rep78 highwgt, col firstonly
      
      -> tabulation of foreign by rep78  
      
      +-------------------+
      | Key               |
      |-------------------|
      |     frequency     |
      | column percentage |
      +-------------------+
      
                 |                   Repair Record 1978
        Car type |         1          2          3          4          5 |     Total
      -----------+-------------------------------------------------------+----------
        Domestic |         2          8         27          9          2 |        48
                 |    100.00     100.00      90.00      50.00      18.18 |     69.57
      -----------+-------------------------------------------------------+----------
         Foreign |         0          0          3          9          9 |        21
                 |      0.00       0.00      10.00      50.00      81.82 |     30.43
      -----------+-------------------------------------------------------+----------
           Total |         2          8         30         18         11 |        69
                 |    100.00     100.00     100.00     100.00     100.00 |    100.00
      
      -> tabulation of foreign by highwgt  
      
      +-------------------+
      | Key               |
      |-------------------|
      |     frequency     |
      | column percentage |
      +-------------------+
      
                 |        highwgt
        Car type |         0          1 |     Total
      -----------+----------------------+----------
        Domestic |        15         37 |        52
                 |     42.86      94.87 |     70.27
      -----------+----------------------+----------
         Foreign |        20          2 |        22
                 |     57.14       5.13 |     29.73
      -----------+----------------------+----------
           Total |        35         39 |        74
                 |    100.00     100.00 |    100.00
      If you really wish to present percentages (without frequencies), you just need to add - nofre1 - option:

      Code:
      . tab2 foreign rep78 highwgt, col firstonly nofreq
      
      -> tabulation of foreign by rep78  
      
                 |                   Repair Record 1978
        Car type |         1          2          3          4          5 |     Total
      -----------+-------------------------------------------------------+----------
        Domestic |    100.00     100.00      90.00      50.00      18.18 |     69.57 
         Foreign |      0.00       0.00      10.00      50.00      81.82 |     30.43 
      -----------+-------------------------------------------------------+----------
           Total |    100.00     100.00     100.00     100.00     100.00 |    100.00 
      
      -> tabulation of foreign by highwgt  
      
                 |        highwgt
        Car type |         0          1 |     Total
      -----------+----------------------+----------
        Domestic |     42.86      94.87 |     70.27 
         Foreign |     57.14       5.13 |     29.73 
      -----------+----------------------+----------
           Total |    100.00     100.00 |    100.00 
      
      .
      Hopefully that helps.
      Last edited by Marcos Almeida; 04 Aug 2019, 08:11.
      Best regards,

      Marcos

      Comment


      • #4
        Check out tabm from tab_chi (SSC). The command name gives a search term for this forum.

        Comment

        Working...
        X