Announcement

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

  • Displaying all the unique categories of a variable

    HI all,

    Please consider the following data set on ocuupation

    Code:
    clear
    
    . input str4 occu
    
              occu
      1. homemaker
      2. retired
      3. student
      4. businessman
      5. daily labourer
      6. student
      7. daily labourer
      8. end
    
    . list
    
         +------+
         | occu |
         |------|
      1. | home |
      2. | reti |
      3. | stud |
      4. | busi |
      5. | dail |
         |------|
      6. | stud |
      7. | dail |
         +------+
    Is there any code that would display these occupational categories uniquely?

    I used the following:
    Code:
    codebook occupation
    and got the output:
    Code:
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    occupation                                                                                                                                                 (unlabeled)
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
                      type:  string (strL)
    
             unique values:  23                       missing "":  0/544,533
    
                  examples:  "Home Maker"
                             "Home-based Worker"
                             "Self employed professional"
                             "Student"
    
                   warning:  variable has embedded blanks
    This does not let me see what these 23 unique values can be.
    Any help would be appreciated.
    Thanks.

  • #2
    Contrary to codebook -- and much else -- I suggest that distinct is a much better word here, as argued within Section 2 of https://www.stata-journal.com/sjpdf....iclenum=dm0042

    Here are some possibilities. Unlike codebook, all these commands will show all distinct categories.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . tab foreign
    
       Car type |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |         52       70.27       70.27
        Foreign |         22       29.73      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    . table foreign
    
    ----------------------
     Car type |      Freq.
    ----------+-----------
     Domestic |         52
      Foreign |         22
    ----------------------
    
    * groups is from the Stata Journal 
    . groups foreign, show(none)
    
      +----------+
      |  foreign |
      |----------|
      | Domestic |
      |  Foreign |
      +----------+

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Contrary to codebook -- and much else -- I suggest that distinct is a much better word here, as argued within Section 2 of https://www.stata-journal.com/sjpdf....iclenum=dm0042

      Here are some possibilities. Unlike codebook, all these commands will show all distinct categories.

      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . tab foreign
      
      Car type | Freq. Percent Cum.
      ------------+-----------------------------------
      Domestic | 52 70.27 70.27
      Foreign | 22 29.73 100.00
      ------------+-----------------------------------
      Total | 74 100.00
      
      . table foreign
      
      ----------------------
      Car type | Freq.
      ----------+-----------
      Domestic | 52
      Foreign | 22
      ----------------------
      
      * groups is from the Stata Journal
      . groups foreign, show(none)
      
      +----------+
      | foreign |
      |----------|
      | Domestic |
      | Foreign |
      +----------+
      thanks a lot. this really helped

      Comment

      Working...
      X