Announcement

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

  • value labels to values

    I am working on modifying an existing data set (IPUMS - HigherEd). This data set contains a number of variables that are numeric and that have value labels--e.g., race_eth == 1 has a value label of white, race_eth == 2 has a value label of black, etc. For our purposes, it would be better to have the value labels as the actual values. I imagine there is some more efficient way of achieving this than to convert everything manually. Any ideas?

  • #2
    see
    Code:
    help decode

    Comment


    • #3
      That's what decode does.

      On the whole, however. a numeric variable with value labels has far more uses than the corresponding string variable. For example, string variables can't in general be used in models and it's harder to graph them. Further, string variables sort alphabetically, which is good for dictionaries but usually poor for statistics.

      Hence what are your purposes and why should string variables be better?

      Comment


      • #4
        You already have it, I mean, what you see is the label.

        Please look at the example below:

        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
        
        . 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
        
        . regress mpg i.foreign
        
              Source |       SS           df       MS      Number of obs   =        74
        -------------+----------------------------------   F(1, 72)        =     13.18
               Model |  378.153515         1  378.153515   Prob > F        =    0.0005
            Residual |  2065.30594        72  28.6848048   R-squared       =    0.1548
        -------------+----------------------------------   Adj R-squared   =    0.1430
               Total |  2443.45946        73  33.4720474   Root MSE        =    5.3558
        
        ------------------------------------------------------------------------------
                 mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
             foreign |
            Foreign  |   4.945804   1.362162     3.63   0.001     2.230384    7.661225
               _cons |   19.82692   .7427186    26.70   0.000     18.34634    21.30751
        ------------------------------------------------------------------------------
        
        . tab foreign, sum(mpg)
        
                    |      Summary of Mileage (mpg)
           Car type |        Mean   Std. Dev.       Freq.
        ------------+------------------------------------
           Domestic |   19.826923   4.7432972          52
            Foreign |   24.772727   6.6111869          22
        ------------+------------------------------------
              Total |   21.297297   5.7855032          74
        Hope that helps.

        P.S.: crossed with Nick's insightful comment, always faster on the trigger.
        Last edited by Marcos Almeida; 17 Apr 2020, 09:11.
        Best regards,

        Marcos

        Comment

        Working...
        X