July 7, 2016

Tabulate with both value and label

Remember when you tabulate, you get the frequency and some statics of the values already labeled (I'm using a data from IMF's Government Finance Statistics database):

. tab soc_src, m

Source - Social |
              Contributions |      Freq.     Percent        Cum.
----------------------------+-----------------------------------
             OECD | General |      1,111       25.38       25.38
  GFS01 | General | Accrual |        139        3.18       28.56
     GFS01 | General | Cash |        219        5.00       33.56
  GFS01 | Central | Accrual |          5        0.11       33.68
     GFS01 | Central | Cash |        297        6.79       40.46
     GFS86 | Central | Cash |         12        0.27       40.74
GFS01 | Budgetary | Accrual |         33        0.75       41.49
   GFS01 | Budgetary | Cash |        148        3.38       44.87
                          . |      2,413       55.13      100.00
----------------------------+-----------------------------------
                      Total |      4,377      100.00

Again the "m" option is so the missing observations are tabulated. Now sometimes when I do a table (or tabulate), I have to write the option "nol" to see the actual values and not the labels assigned to them:

. tab soc_src, nol

Source - |
     Social |
Contributio |
         ns |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      1,111       56.57       56.57
          2 |        139        7.08       63.65
          3 |        219       11.15       74.80
          4 |          5        0.25       75.05
          5 |        297       15.12       90.17
          6 |         12        0.61       90.78
          7 |         33        1.68       92.46
          8 |        148        7.54      100.00
------------+-----------------------------------
      Total |      1,964      100.00

Now why not both? I mean, what does the value "0" refer to again? How about "8"? Well if you use the command "FRE", written by Ben Jann, tabulation is much clearer:

. fre soc_src

soc_src -- Source - Social Contributions
-----------------------------------------------------------------------------------
                                      |      Freq.    Percent      Valid       Cum.
--------------------------------------+--------------------------------------------
Valid   0 OECD | General              |       1111      25.38      56.57      56.57
        2 GFS01 | General | Accrual   |        139       3.18       7.08      63.65
        3 GFS01 | General | Cash      |        219       5.00      11.15      74.80
        4 GFS01 | Central | Accrual   |          5       0.11       0.25      75.05
        5 GFS01 | Central | Cash      |        297       6.79      15.12      90.17
        6 GFS86 | Central | Cash      |         12       0.27       0.61      90.78
        7 GFS01 | Budgetary | Accrual |         33       0.75       1.68      92.46
        8 GFS01 | Budgetary | Cash    |        148       3.38       7.54     100.00
        Total                         |       1964      44.87     100.00           
Missing .                             |       2413      55.13                      
Total                                 |       4377     100.00                      
-----------------------------------------------------------------------------------

To download the program, just type:

ssc install fre

There was once another user-made program that does a similar thing called "TABL," but it's no longer available in the servers anymore.

Anyway, more later.