Announcement

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

  • How do i list ALL underlying codes for a variabel?

    I have a long list of diagnostic codes, which all have an underlying code that i need to use when want to write a command with that scecific diagnostic code. The problem is that when using the command "codebook", it only lists four examples of the underlying code. My question is, how do i see the rest of the codes?

    I have tried the command "codebook diagnosis, all". But i get the same result

  • #2
    I mostly have no idea what you are talking about, you should use -dateex- to show how your data looks like.

    But a wild guess, if you are talking about variables, you can change between seeing the labels and the underlying values by

    Code:
    . sysuse auto
    (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
    
    . tab foreign, nolabel
    
       Car type |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         52       70.27       70.27
              1 |         22       29.73      100.00
    ------------+-----------------------------------
          Total |         74      100.00

    Comment


    • #3
      Two additional options:
      1) You can list the value labels attached to each value. Identify the value label if you don't know it with the describe command followed by the lab list command. This will also show value labels that may not have corresponding values in the data.
      Code:
      sysuse auto
      desc foreign
      lab list origin
      2) You can install and use Ben Jann's fre command available on SSC. The all option will list all values and their value labels (along with frequencies) in the data.
      Code:
      ssc install fre
      fre foreign, all
      Stata/MP 14.1 (64-bit x86-64)
      Revision 19 May 2016
      Win 8.1

      Comment


      • #4
        Building on Joro's example and your familiarity with the codebook command, you need to use the label list command for a definitive list of value/label pairs.
        Code:
        . codebook foreign
        
        ------------------------------------------------------------------------------------------------
        foreign                                                                                 Car type
        ------------------------------------------------------------------------------------------------
        
                          type:  numeric (byte)
                         label:  origin
        
                         range:  [0,1]                        units:  1
                 unique values:  2                        missing .:  0/74
        
                    tabulation:  Freq.   Numeric  Label
                                    52         0  Domestic
                                    22         1  Foreign
        
        . label list origin
        origin:
                   0 Domestic
                   1 Foreign
        Also, see the following technique for using a value corresponding to a value label in an expression. (I can't tell you where to read about this because I can never find this in the Stata documentation or help files.)
        Code:
        . tab foreign if foreign=="Domestic":origin
        
           Car type |      Freq.     Percent        Cum.
        ------------+-----------------------------------
           Domestic |         52      100.00      100.00
        ------------+-----------------------------------
              Total |         52      100.00
        Added in edit: Aha! This is documented in the Stata User's Guide PDF in section 13.11. I don't think you'll find it in the output of any help command.
        Last edited by William Lisowski; 19 Jan 2019, 09:29.

        Comment


        • #5
          Here is how elabel (SSC) makes these things simpler.

          Code:
          sysuse auto
          elabel list (foreign)
          return list
          Code:
          . sysuse auto
          (1978 Automobile Data)
          
          . elabel list (foreign)
          origin:
                     0 Domestic
                     1 Foreign
          
          . return list
          
          scalars:
                          r(min) =  0
                          r(max) =  1
                     r(hasemiss) =  0
                       r(nemiss) =  0
                            r(k) =  2
          
          macros:
                         r(name) : "origin"
                       r(values) : "0 1"
                       r(labels) : ""Domestic" "Foreign""
          
          . 
          end of do-file
          Best
          Daniel

          Comment


          • #6
            Thank you so much for the help guys! You saved me alot of time
            The command "label list origin" was exactly what i was looking for.

            God bless

            Comment

            Working...
            X