Announcement

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

  • Changing from a byte to a numeric variable

    Hi, I am a new user of Stata and would appreciate any help I can get

    I have a varible called v719

    it is a response to the question "whether respondent works for family member, someone else or is self-employed"

    the possible values are for family member, self-employed, for someone else

    i want to convert all reponses that are not for family member to 1 and all response for a family member to 0

    However when i tried to do this i got an error- (see below)

    How do I convert these values into the numeric form?

    I am using Stata/MP 17.0

    generate employment=0

    . replace employment=1 if v719=="self-employed"
    type mismatch
    r(109);

    . replace employment=1 if v719==self-employed
    self not found
    r(111);

    . describe v719

    Variable Storage Display Value
    name type format label Variable label
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
    v719 byte %8.0g V719 respondent works for family, others, self


  • #2
    nevermind i figured it out, the summerize command told me there were 3 numbers

    sadly the documentation for the data doesn't seem to say which number is which but that's my problem

    also when you view the data it shows the words not numbers for v719
    Last edited by Angus Greaves; 01 May 2022, 06:04.

    Comment


    • #3
      The output of the describe command tells you that the variable named v719 (lower-case v) has a value label V719 (upper-case V). So when you view the data you are looking at the value labels and not the numeric values. The output of
      Code:
      help label
      tells you that
      Code:
      label list V719
      will show you the definition of the value lable, so you know which value corresponds to which label.

      If you're looking at a variable that you don't fully understand, as in this case, the codebook command will help more than the simple summarize or describe command. Perhaps the source of your data expected that users would start by creating a codebook for the dataset, and that is why the documentation doesn't tell you which number is which.
      Code:
      codebook v719
      or to get a codebook for all the variables
      Code:
      codebook
      but do look at the output of
      Code:
      help codebook
      to learn about the options that can be used with it.

      Comment

      Working...
      X