Announcement

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

  • PANIC ATTACK: difference between value labels and values I want to use

    Hi everyone!

    I have changed my data recently and am struggling with an issue, your help will be much appreciated.
    I am a Stata novice so I am sorry if my question seems stupid.

    Here are the symptoms of my problem: 1) All my data in Browse appears in blue, meaning that it is numerical.
    2) When I just run the Browse command and look at it, everything is ok, the numbers that I want for each variables appear in the column. Great.
    3) When I click individually on the squares where the numbers are, the number that appears in the white bar on the top (next to the variable name) is completely different.
    4) Thus whenever I run a command, Stata uses the number in the white bar, and not the number that I want, that is: the number that appears in the column.


    From what I have been searching: this means that I have some "value labels" attached to my variables. I didn't do that on purpose and I want to get rid of them.
    People recommend to use "label drop" and suddenly all the blue numbers are replaced by the value labels and become black. But I want to do the reverse, I want to get rid of the numbers in the white bar and simply use the numbers that I get in the columns. How can I do that?

    Take a look at the image attached to see the problem!

    Thank you very very much!


  • #2
    What do you get if you issue the commands:
    list m03status in 1/5
    describe m03status

    Comment


    • #3
      I get this:

      Comment


      • #4
        It seems that variables that should be numeric have been encoded into numeric variables with value labels in which the correct values are the value labels and the assigned integer values are otherwise not important.

        The root of this is probably use of comma as decimal point at some earlier stage. (You don't explain where the dataset comes from or how you read it into Stata or precisely how you changed the dataset: these are important details for diagnosis!)

        You want to reverse that. Study this sequence and the help for decode and destring:

        Code:
        . clear
        
        . set obs 1
        number of observations (_N) was 0, now 1
        
        . gen exp = "1,23"
        
        . encode exp, gen(exp2)
        
        . l
        
             +-------------+
             |  exp   exp2 |
             |-------------|
          1. | 1,23   1,23 |
             +-------------+
        
        . d
        
        Contains data
          obs:             1                          
         vars:             2                          
         size:             8                          
        -------------------------------------------------------------------------------
                      storage   display    value
        variable name   type    format     label      variable label
        -------------------------------------------------------------------------------
        exp             str4    %9s                  
        exp2            long    %8.0g      exp2      
        -------------------------------------------------------------------------------
        Sorted by:
             Note: Dataset has changed since last saved.
        
        . decode exp2, gen(exp3)
        
        . l
        
             +--------------------+
             |  exp   exp2   exp3 |
             |--------------------|
          1. | 1,23   1,23   1,23 |
             +--------------------+
        
        . d
        
        Contains data
          obs:             1                          
         vars:             3                          
         size:            12                          
        -------------------------------------------------------------------------------
                      storage   display    value
        variable name   type    format     label      variable label
        -------------------------------------------------------------------------------
        exp             str4    %9s                  
        exp2            long    %8.0g      exp2      
        exp3            str4    %9s                  
        -------------------------------------------------------------------------------
        Sorted by:
             Note: Dataset has changed since last saved.
        
        . destring exp3, gen(exp4) dpcomma
        exp3 has all characters numeric; exp4 generated as double
        
        . l
        
             +---------------------------+
             |  exp   exp2   exp3   exp4 |
             |---------------------------|
          1. | 1,23   1,23   1,23   1.23 |
             +---------------------------+

        Comment


        • #5
          From the -list- command, the series is correctly recorded and will be used as such.
          From the -describe- command, it has been formatted to display with zero decimal values. So it rounds the display from 2.7 to 3

          Comment


          • #6
            You were right and I managed to rectify the mistake! Thank you so much for your help Nick and Eric, it is really appreciated!

            Comment

            Working...
            X