Announcement

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

  • What is the difference between tab and tab1, and how to retrieve the number of difference value of variable of interest?

    Today I seach for the use of -tab- command. I saw the -tab1- command, when I use both of them for the variable location in my data, the result are the same between them, I am wondering whether these two commands are totally the same?

    Code:
    tab location
    tab1 location
    Apart from that, when I run tab location, I have the result as below

    Code:
     tab location
    Code:
                 location |      Freq.     Percent        Cum.
    -----------------------+-----------------------------------
               Afghanistan |        505        0.74        0.74
                    Angola |        525        0.77        1.50
                 Argentina |        559        0.82        2.32
                     Aruba |        151        0.22        2.54
                 Australia |        559        0.82        3.36
                   Austria |        549        0.80        4.16
                   Bahrain |        550        0.80        4.96
                Bangladesh |        542        0.79        5.75
                  Barbados |        528        0.77        6.52
                   Belarus |        546        0.80        7.32
                   Belgium |        559        0.82        8.14
                    Belize |        522        0.76        8.90
                     Benin |        529        0.77        9.67
                   Bolivia |        534        0.78       10.45
    Bosnia and Herzegovina |        540        0.79       11.24
                  Botswana |        515        0.75       11.99
                    Brazil |        548        0.80       12.79
                  Bulgaria |        537        0.78       13.57
              Burkina Faso |        535        0.78       14.35
                  Cambodia |        559        0.82       15.17
                  Cameroon |        539        0.79       15.96
                    Canada |        559        0.82       16.77
                Cape Verde |        522        0.76       17.54
                     Chile |        551        0.80       18.34
                  Colombia |        539        0.79       19.13
                Costa Rica |        539        0.79       19.91
                   Croatia |        549        0.80       20.71
                   Czechia |        546        0.80       21.51
                   Denmark |        559        0.82       22.33
        Dominican Republic |        544        0.79       23.12
                   Ecuador |        544        0.79       23.92
                     Egypt |        559        0.82       24.73
               El Salvador |        526        0.77       25.50
                   Estonia |        559        0.82       26.32
                      Fiji |        559        0.82       27.13
                   Finland |        556        0.81       27.94
                    France |        559        0.82       28.76
                     Gabon |        531        0.78       29.53
                   Georgia |        503        0.73       30.27
                   Germany |        559        0.82       31.09
                     Ghana |        531        0.78       31.86
                    Greece |        550        0.80       32.66
                 Guatemala |        557        0.81       33.48
                     Haiti |        525        0.77       34.24
                  Honduras |        534        0.78       35.02
                 Hong Kong |        559        0.82       35.84
                   Hungary |        542        0.79       36.63
                     India |        559        0.82       37.45
                 Indonesia |        543        0.79       38.24
                      Iraq |        550        0.80       39.04
                   Ireland |        545        0.80       39.84
                    Israel |        554        0.81       40.65
                     Italy |        559        0.82       41.46
                   Jamaica |        534        0.78       42.24
                     Japan |        559        0.82       43.06
                    Jordan |        542        0.79       43.85
                Kazakhstan |        532        0.78       44.62
                     Kenya |        539        0.79       45.41
                    Kuwait |        550        0.80       46.21
                Kyrgyzstan |        527        0.77       46.98
                      Laos |        521        0.76       47.74
                    Latvia |        547        0.80       48.54
                   Lebanon |        553        0.81       49.35
                     Libya |        541        0.79       50.14
             Liechtenstein |        515        0.75       50.89
                 Lithuania |        545        0.80       51.69
                Luxembourg |        550        0.80       52.49
                  Malaysia |        559        0.82       53.31
                      Mali |        520        0.76       54.07
                     Malta |        559        0.82       54.88
                 Mauritius |        527        0.77       55.65
                    Mexico |        559        0.82       56.47
                   Moldova |        537        0.78       57.25
                  Mongolia |        535        0.78       58.03
                   Morocco |        559        0.82       58.85
                Mozambique |        523        0.76       59.61
                   Namibia |        531        0.78       60.39
                     Nepal |        559        0.82       61.20
               Netherlands |        547        0.80       62.00
               New Zealand |        546        0.80       62.80
                 Nicaragua |        526        0.77       63.57
                     Niger |        525        0.77       64.33
                   Nigeria |        546        0.80       65.13
                    Norway |        549        0.80       65.93
                      Oman |        550        0.80       66.73
                  Pakistan |        549        0.80       67.54
                    Panama |        536        0.78       68.32
          Papua New Guinea |        522        0.76       69.08
                  Paraguay |        538        0.79       69.87
                      Peru |        559        0.82       70.68
               Philippines |        559        0.82       71.50
                    Poland |        541        0.79       72.29
                  Portugal |        550        0.80       73.09
                     Qatar |        545        0.80       73.89
                   Romania |        548        0.80       74.69
                    Russia |        559        0.82       75.50
                    Rwanda |        531        0.78       76.28
              Saudi Arabia |        543        0.79       77.07
                   Senegal |        546        0.80       77.87
                    Serbia |        503        0.73       78.60
                 Singapore |        559        0.82       79.42
                  Slovakia |        539        0.79       80.20
                  Slovenia |        559        0.82       81.02
              South Africa |        559        0.82       81.84
               South Korea |        559        0.82       82.65
                     Spain |        559        0.82       83.47
                 Sri Lanka |        559        0.82       84.28
                    Sweden |        559        0.82       85.10
               Switzerland |        549        0.80       85.90
                    Taiwan |        559        0.82       86.72
                Tajikistan |        484        0.71       87.42
                  Tanzania |        529        0.77       88.20
                  Thailand |        559        0.82       89.01
                      Togo |        541        0.79       89.80
       Trinidad and Tobago |        531        0.78       90.58
                    Turkey |        534        0.78       91.36
                    Uganda |        524        0.76       92.12
                   Ukraine |        542        0.79       92.91
      United Arab Emirates |        559        0.82       93.73
            United Kingdom |        559        0.82       94.54
             United States |        559        0.82       95.36
                   Uruguay |        532        0.78       96.14
                 Venezuela |        531        0.78       96.91
                   Vietnam |        559        0.82       97.73
                     Yemen |        504        0.74       98.46
                    Zambia |        527        0.77       99.23
                  Zimbabwe |        525        0.77      100.00
    -----------------------+-----------------------------------
                     Total |     68,502      100.00
    What I want is I want to know how many different location in this table, I did search the code "tab" but I have not yet found out what I want, could you please help me to sort it out?
    Thanks in advance

  • #2
    Second question first. After running -tab variable-, you can see the number of distinct values of variable by running -return list-, where it will show up as r(r). If you need to save that number for later use, the sequence would be:

    Code:
    tab variable
    local n_distinct_values = r(r)
    First question second. When you specify only a single variable, -tab- and -tab1- do the same thing. But if you specify a longer variable list, you get a sequence of tabulations, all of which involve the first variable cross-tabulated with each of the subsequent variables separately. That is, -tab1 var1 var2 var3 var4- is equivalent to -tab var1- followed by -tab var2- followed by -tab var3- followed by -tab var4-.

    Comment


    • #3
      Thanks Clyde Schechter , it works

      Comment


      • #4
        Clyde Schechter could you explain the difference between -tab- versus -tab1- again please? i am new to Stata and i have seen my professor using both tab's but i don't understand the difference between the two and when i should use them. I am also new to coding lingo so if you can explain, please explain it thoroughly. thank you.

        Comment


        • #5
          If you are interested in the frequency distribution of the different levels of just one variable, tab and tab1 will do the same thing:
          Code:
          . tab 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
          
          . tab1 rep78
          
          -> 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
          If you are interested in two variables and you want the separate distributions of each, then you must use -tab1- for that. -tab- will give you a cross-tabulation of the two variables, that is, it will show you the frequency of each combination of levels of the two variables. Watch:
          Code:
          . tab1 rep78 foreign
          
          -> 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
          
          -> tabulation of foreign  
          
           Car origin |      Freq.     Percent        Cum.
          ------------+-----------------------------------
             Domestic |         52       70.27       70.27
              Foreign |         22       29.73      100.00
          ------------+-----------------------------------
                Total |         74      100.00
          
          . tab rep78 foreign
          
              Repair |
              record |      Car origin
                1978 |  Domestic    Foreign |     Total
          -----------+----------------------+----------
                   1 |         2          0 |         2
                   2 |         8          0 |         8
                   3 |        27          3 |        30
                   4 |         9          9 |        18
                   5 |         2          9 |        11
          -----------+----------------------+----------
               Total |        48         21 |        69
          If you have three or more variables for which you want separate tables of the frequency of each value, -tab1- will do it. Voila:
          Code:
          . tab1 foreign rep78 headroom
          
          -> tabulation of foreign  
          
           Car origin |      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
          
          -> tabulation of headroom  
          
             Headroom |
                (in.) |      Freq.     Percent        Cum.
          ------------+-----------------------------------
                  1.5 |          4        5.41        5.41
                  2.0 |         13       17.57       22.97
                  2.5 |         14       18.92       41.89
                  3.0 |         13       17.57       59.46
                  3.5 |         15       20.27       79.73
                  4.0 |         10       13.51       93.24
                  4.5 |          4        5.41       98.65
                  5.0 |          1        1.35      100.00
          ------------+-----------------------------------
                Total |         74      100.00
          You might wonder what -tab- does when given three or more variables. It gives you an error message. -tab- can only be used with 1 or 2 variables. Here:
          Code:
          . tab rep78 foreign headroom
          too many variables specified
          r(103);

          Comment


          • #6
            in need to call in a dataset from google form to stata
            ,

            step 1:
            Publish your spreadsheet as Excel to access all tabs
            Go on your spreadsheet then click File >> Publish to the web >> Link >> Entire Document | Microsoft Excel(.xlsx) >> Publish
            ,

            Step 2: : Create an Excel copy of the spreadsheet in memory.
            Code:

            tempfile gsheet
            copy "published spreadsheet link from above" `gsheet', replace
            ,

            step 3: Call the Excel copy created in memory.
            Code:
            import excel using `gsheet', first sheet("tabname") clear
            ,

            I applied step 1, steps 2 and 3 but I still can't get it right
            ,

            [QUOTE] 1. Is the coppied to be saved as tempfile ? 2. And then you call in the tempfile sheet by copy past on command window or you 3. call in using the dofile format ?[/Q UOTE]

            I wish to have a clearer picture of it.
            courtesy: Narcisse Mutabaruka; 30 Sep 2021, 12:03.

            Comment

            Working...
            X