Announcement

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

  • Value label

    Hi all,

    I've been struggling with attaching a label to a recoded variable. For a report, I am working with a categorical variable named 'country', with the variable label COUNTRY. This variable lists various European countries (for example: 26 = Poland, with the value label PL - Poland). I have had to do some recoding, so that the separate values for East- and West-Germany (East-Germany having the value '4', and West-Germany having the value '14') were merged into one value, namely 0. For this, I have used the following command:

    recode country (4 14 = 0)

    In order to give this new value 0 the label of Germany, I have used the following code.

    label define country 0 "DE - Germany"

    However, even though this label is accepted as a command, Stata does not seem to recognise the new label for this recoded variable. If I try to make a table, this is what it looks like:
    Click image for larger version

Name:	stata1.png
Views:	1
Size:	20.6 KB
ID:	1684328




    In other words, all it shows is the new recoded value, and not its label. Similarly, if I type in the command codebook country, Stata informs me that one nonmissing value is not labelled.
    Click image for larger version

Name:	stata2.png
Views:	1
Size:	30.3 KB
ID:	1684329



    Would anyone be able to help me out in properly attaching the value label to this new recoded value? I would be very grateful, as I've been scouring the internet for answers for hours now!

    Thank you in advance
    Last edited by Roeland Endtz; 04 Oct 2022, 15:40.

  • #2
    What you want is to modify an existing label, not to define a new one.

    Code:
    lab def COUNTRY 0 "DE - Germany", modify

    Comment


    • #3
      Hi Andrew, thank you so much for your help!! For some reason I thought that I had tried it like this already, but apparently not - it finally works now. I really appreciate it.

      Comment


      • #4
        You would probably also want to delete values 4 and 14 from the value label. For tasks like these, also see elabel (from SSC or GitHub). For example,

        Code:
        elabel recode (country) (4 14 = 0 "Germany") , recodevarlist
        will modify the value label attached to country, the variable country, and all other variables, if any, that have the value label COUNTRY attached.

        Comment

        Working...
        X