Announcement

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

  • Replacing variable values with actual values stata in edit

    Hi all,
    I was wondeirng if there is a quick way to replace the values that stata assigns to variables with their actual variables? For example in the attachment below, how can I change the value of 45 from 197 to 45, and then the same for the other values. Likewise, I would like to change "Yes" and "No" to 2 and 1 respectively.

    Thanks
    Click image for larger version

Name:	Annotation 2020-03-16 132532.png
Views:	1
Size:	39.4 KB
ID:	1541504

  • #2
    BUSHR_1 looks to me like a variable that should be numeric but somehow has been encoded incorrectly. Some of your other variables look messed up too with a funny mix of value labels that code categories and numeric text in value labels.

    If so, asking about editing is possibly the wrong question. You may need to redo your entire data input to have any chance of intelligible results. I know that's unwelcome news.

    Comment


    • #3
      Hi Nick, the data was all originally stored as strings and so I ran
      Code:
      multencode ACTHR ACTPOT ACTUOT BACTHR BUSHR ED13WK ED4WK ERNFILT EVEROT FTPT ILLFRI ILLMON ILLWK LESPAY LESPAY2 LESPAY3 OVHRS T4PURP T4WORK TOTAC1 TOTAC2 TOTHRS TOTUS1 TOTUS2 TRNOPP11 TTACHR TTUSHR UNDEMP UNDHRS YLESS6, gen(ACTHR_1 ACTPOT_1 ACTUOT_1 BACTHR_1 BUSHR_1 ED13WK_1 ED4WK_1 ERNFILT_1 EVEROT_1 FTPT_1 ILLFRI_1 ILLMON_1 ILLWK_1 LESPAY_1 LESPAY2_1 LESPAY3_1 OVHRS_1 T4PURP_1 T4WORK_1 TOTAC1_1 TOTAC2_1 TOTHRS_1 TOTUS1_1 TOTUS2_1 TRNOPP11_1 TTACHR_1 TTUSHR_1 UNDEMP_1 UNDHRS_1 YLESS6_1)
      .
      Was this the wrong thing to do?

      Comment


      • #4
        On the evidence yes. multencode (SSC, and looking familiar somehow) is the only the right thing to do if you know that all the variables you specify should be labelled the same way. That's rare for all the variables in a dataset.

        What's much more common that all variables arriving as string arises for one or more of the following

        1. Metadata or text commentary being imported as data, e.g column headers.

        2. Non-standard codes for missing values, as compared with Stata standards.

        I'd go back to the original, frankly.

        I would bear some of the responsibility if the help file for multencode was unclear on this. Naturally I don't think so, particularly given warnings such as

        The same set of value labels is used for all the new variables.

        Do not use multencode if strvarlist contains numbers that merely happen to be stored as strings. Instead, use destring.

        Comment


        • #5
          Ok then, thanks for the help

          Comment


          • #6
            You didn't specify a set of value labels that multencode should use. It looks as if you have mostly numbers in your data except for

            Yes
            No
            Does not apply
            Don't know/refusal

            and perhaps some other codes.

            Any variable that consists only of such values is fine for multencode. The others may need you to define extended missing values.

            Comment

            Working...
            X