Announcement

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

  • how to display distinct values of variables?

    I know use -distinct- command to know the number of distinct values of variables. How to list these distinct values? I want to know their IDs.

  • #2
    Your question is not entirely clear to me, especially given the reference to both 'values' and 'IDs'. Might -duplicates- help you?

    Comment


    • #3
      This should give you all distinct values, their frequency and percentage:
      Code:
      * If not already installed (Jann, B. (2007). fre: Stata module to display one-way frequency table.):
      ssc install fre
      
      fre variable , all
      
      * Consult the help file for options:
      h fre
      Last edited by ericmelse; 11 Mar 2020, 03:12. Reason: The reference to the community-contributed command fre was added
      http://publicationslist.org/eric.melse

      Comment


      • #4
        Some long-term readers may know of one of my personal hobby-horses that the word unique should often be replaced by distinct. Here I wonder if it's the other way round, that there is a need to find values that really are unique, i.e. occur once only.

        Here is a silly example but some possibly useful technique. Which values occur just once and what are their identifiers?


        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . bysort mpg : gen select = _N == 1
        
        . list mpg make if select
        
             +----------------------+
             | mpg   make           |
             |----------------------|
         67. |  29   Chev. Chevette |
         70. |  31   Toyota Corolla |
         71. |  34   Plym. Champ    |
         74. |  41   VW Diesel      |
             +----------------------+
        #3 ericmelse fre is from SSC. Please remember to explain where community-contributed commands you refer to come from. fre is excellent but tabulate does what you outline too without obliging a download.

        #1 distinct is community-contributed too, from the Stata Journal.

        Comment


        • #5
          I tagged the first obs. of each ids and do list for multiple variables as below.

          Code:
          . list Company Industry01 Industry02 Industry03 if check != 1
          
                +-----------------------------------------------------------------------------------------------------------------+
                |                     Company                     Industry01                     Industry02            Industry03 |
                |-----------------------------------------------------------------------------------------------------------------|
            26. |                   4Paradigm                             AI                  Cybersecurity                       |
            27. |                   4Paradigm                             AI                  Cybersecurity                       |
            28. |                   4Paradigm                             AI                  Cybersecurity                       |
            29. |                   4Paradigm                             AI                  Cybersecurity                       |
            30. |                   4Paradigm                             AI                  Cybersecurity                       |
                |-----------------------------------------------------------------------------------------------------------------|
            91. |                     Actifio                 BI & Analytics                       Big Data                       |
            92. |                     Actifio                 BI & Analytics                       Big Data                       |
            93. |                     Actifio                 BI & Analytics                       Big Data                       |
            94. |                     Actifio                 BI & Analytics                       Big Data                       |
            95. |                     Actifio                 BI & Analytics                       Big Data                       |
                |-----------------------------------------------------------------------------------------------------------------|
            96. |                     Actifio                 BI & Analytics                       Big Data                       |
            97. |                     Actifio                 BI & Analytics                       Big Data                       |
            98. |                     Actifio                 BI & Analytics                       Big Data                       |
          
          
          . bysort Company: gen first_obs = 1 if _n == 1
          . list Company Industry01 Industry02 Industry03 if check != 1 & first_obs == 1
          
                +-----------------------------------------------------------------------------------------------------------------+
                |                     Company                     Industry01                     Industry02            Industry03 |
                |-----------------------------------------------------------------------------------------------------------------|
            26. |                   4Paradigm                             AI                  Cybersecurity                       |
            91. |                     Actifio                 BI & Analytics                       Big Data                       |

          Comment

          Working...
          X