Announcement

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

  • Change numeric value of a variable while keeping the label value

    Dear Statalist,

    Using Stata 14 I am trying to change the numeric value of one variable while keeping the value label:
    Code:
    tab x
    gives the value label of "yes".
    Code:
    tab x, nolabel
    gives the numeric value of "111".


    Now I want to change "111" to "1" without disregarding the value label and having to create a new variable. It would be something like the following command (which unfortunately does not work.):
    Code:
    recode consent (111 = 1 yes)
    Any help is very much appreciated!

  • #2
    This example may help.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . keep foreign
    
    . describe foreign
    
                  storage   display    value
    variable name   type    format     label      variable label
    -------------------------------------------------------------------
    foreign         byte    %8.0g      origin     Car type
    
    . tab foreign
    
       Car type |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |         52       70.27       70.27
        Foreign |         22       29.73      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    . recode foreign (1=111)
    (foreign: 22 changes made)
    
    . describe foreign
    
                  storage   display    value
    variable name   type    format     label      variable label
    -------------------------------------------------------------------
    foreign         int     %8.0g      origin     Car type
    
    . tab foreign
    
       Car type |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |         52       70.27       70.27
            111 |         22       29.73      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    . label define origin 111 "Foreign", add
    
    . tab foreign
    
       Car type |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |         52       70.27       70.27
        Foreign |         22       29.73      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    .

    Comment


    • #3
      Hi,
      how about:

      recode consent 111=1
      label define consent 1"Yes" [plus other values"labels"], replace

      Comment


      • #4
        Perfect, thanks!!!

        Comment

        Working...
        X