Announcement

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

  • How replace text value of variable with number

    So I have a variable education that has lots of values in text specifying 'bachelor 1', 'bachelor 2' and 'bachelor 3' for each respondent. However, I want to change them to respectively 1, 2 and 3 so that I can adequately use the variable in a regression analysis.

    How can I replace these text variables with specific numbers? (Note: stata says that the text values are numerical, which I do find rather weird)

  • #2
    Code:
    help encode

    Comment


    • #3
      (Note: stata says that the text values are numerical, which I do find rather weird)
      This suggests that your data are already encoded with value labels. Here is an example of such a variable from a dataset included with Stata.
      Code:
      . sysuse auto, clear
      (1978 automobile data)
      
      . describe foreign
      
      Variable      Storage   Display    Value
          name         type    format    label      Variable label
      ------------------------------------------------------------------------------------------------
      foreign         byte    %8.0g      origin     Car origin
      
      . tab foreign
      
       Car origin |      Freq.     Percent        Cum.
      ------------+-----------------------------------
         Domestic |         52       70.27       70.27
          Foreign |         22       29.73      100.00
      ------------+-----------------------------------
            Total |         74      100.00
      
      . tab foreign, nolabel
      
       Car origin |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         52       70.27       70.27
                1 |         22       29.73      100.00
      ------------+-----------------------------------
            Total |         74      100.00
      
      . label list origin
      origin:
                 0 Domestic
                 1 Foreign
      
      .

      Comment

      Working...
      X