Announcement

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

  • Change the lab value names but retain the values

    Dear All,

    I need some assistance with changing the value label names in one of my datasets. The issue is that both datasets I want to merge use the same value label names, and when I merge them, the value labels from the using dataset are lost.

    Specifically, in this dataset the variables are named q1, q2, q3, q4 … up to q18. When I run label list, the label names currently appear as q1, q2, q3, etc. I would like to change these label names so that I can merge the datasets without losing the value labels, but I still want to retain the actual label definitions so that I can merge with the other data that has the same val names q1, q2 ....

    Could you please advise on how to do this properly?


    clear
    input byte q1 long q2 byte(q3 q4) str35 q5 byte q6 str27 q7 byte(q8 q10 q11)
    2 1536 2 2 "8000" 2 "7" 3 3 4
    2 1536 2 2 "8000" 1 "34" 3 3 4
    2 1539 2 2 "8000" 1 "34" 4 4 4
    2 1536 2 2 "8000" 1 "34" 1 3 2
    2 1535 2 3 "8000" 2 "34" 3 3 4
    2 515 2 2 "8000" 3 "30" 1 3 3
    2 1536 2 2 "8000" 2 "34" 3 4 4
    2 1536 2 2 "8000" 1 "34" 3 3 2
    2 1539 4 2 "8000" 1 "28" 3 4 2
    2 1536 2 2 "8000" 1 "34" 3 2 4
    2 1536 2 3 "8000" 1 "34" 1 3 2
    2 313 2 4 "8000" 2 "30" 1 4 2
    2 1536 2 3 "8000" 1 "34" 3 3 1
    2 1536 2 3 "8000" 2 "12,26,40,54" 3 3 4
    2 1536 2 2 "8000" 4 "34" 1 3 4
    2 1536 2 3 "8000" 2 "34" 2 4 4
    2 1536 2 3 "8000" 1 "34" 3 1 3
    2 1539 2 2 "8000" 1 "34" 3 4 4
    2 1539 2 2 "8000" 3 "7" 3 4 2
    2 1536 2 4 "8000" 4 "34" 1 1 3
    2 1536 2 2 "8000" 1 "34" 3 2 3
    2 1536 2 2 "8000" 2 "34" 3 3 3
    2 1536 2 4 "8000" 3 "20" 2 1 2
    2 1536 2 2 "8000" 1 "34" 3 3 2
    2 1536 2 2 "8000" 1 "34" 1 3 4
    2 1536 2 3 "8000" 1 "32,39,45" 2 3 4
    2 1536 2 3 "8000" 3 "33" 3 3 4
    2 1516 4 2 "6000" 1 "13" 2 2 2
    2 1536 1 2 "8000" 4 "34" 3 3 4
    2 1536 2 2 "8000" 4 "7" 1 2 4
    2 1536 2 2 "8000" 2 "33" 1 4 4
    2 1036 2 3 "8000" 1 "34" 3 1 4
    2 546 2 2 "8000" 1 "34" 3 3 4
    1 1036 2 4 "8000" 1 "7,15,22" 2 1 2
    2 1539 2 2 "8000" 1 "34" 1 3 2
    2 1536 2 2 "8000" 1 "34" 1 1 4
    2 1536 2 2 "8000" 1 "34" 3 3 4
    2 1516 2 2 "8000" 1 "34" 3 1 2
    2 1536 2 3 "8000" 2 "33" 1 2 3
    2 1536 2 3 "8000" 1 "28" 1 3 4
    2 1530 3 1 "8000" 4 "34" 3 1 4
    2 1536 2 2 "8000" 1 "34" 1 3 4
    2 1536 2 . "" 1 "34" 3 4 4
    2 . 2 4 "Friday" 1 "" 2 2 3
    2 1536 2 2 "8000" 4 "34" 3 3 4
    2 1536 2 3 "8000" 1 "8" 3 3 2
    2 1536 2 2 "6000" 1 "28" 2 2 2
    2 1536 2 2 "8000" 3 "34" 3 3 4
    2 10536 2 2 "8000" 1 "34" 2 3 2
    2 812 2 4 "8000" 1 "16" 1 2 3
    2 1536 2 3 "8000" 1 "33" 2 4 4
    2 1536 2 1 "8000" 1 "34" 1 3 2
    2 1536 2 3 "8000" 1 "34" 3 3 2
    2 1536 2 2 "8000" 1 "34" 1 4 2
    2 134 2 3 "Friday" 2 "30" 2 2 4
    2 171 2 2 "8000" 1 "34" 2 1 4
    2 1736 2 2 "8000" 4 "34" 3 3 3
    2 1536 2 2 "8000" 1 "34" 4 1 4
    2 1519 2 2 "8000" 1 "34" 1 4 2
    2 1536 2 2 "8000" 1 "34" 1 3 2
    2 1536 2 2 "8000" 1 "34" 3 3 4
    2 1539 2 4 "8000" 4 "34" 3 4 3
    2 341 2 2 "8000" 3 "34" 3 4 2
    2 1536 2 2 "8000" 1 "34" 3 2 4
    2 1536 2 2 "8000" 1 "34" 3 3 4
    2 1536 2 2 "8000" 1 "35" 3 3 2
    2 1806 2 3 "8000" 1 "34" 1 3 4
    2 1536 2 2 "8000" 1 "34" 3 3 2
    2 1536 2 2 "8000" 1 "34" 2 2 2
    2 145 2 3 "8000" 2 "34" 3 1 3
    2 1536 2 2 "8000" 1 "7" 1 1 2
    2 1034 2 2 "8000" 2 "27" 1 2 4
    2 1026 2 2 "8000" 2 "34" 1 3 2
    2 1536 1 3 "8000" 4 "27" 2 3 3
    2 1536 2 3 "8000" 2 "34" 1 1 4
    2 1536 2 4 "8000" 2 "33" 3 1 2
    2 1536 2 3 "8000" 1 "34" 2 2 4
    2 1536 2 2 "8000" 1 "34" 3 3 2
    2 1536 2 3 "8000" 1 "34" 2 1 2
    2 1536 2 4 "8000" 4 "34" 1 3 2
    2 1536 2 2 "8000" 1 "34" 3 1 4
    2 1536 2 3 "8000" 2 "34" 2 1 4
    1 1536 2 2 "8000" 1 "34" 3 3 2
    2 1536 2 2 "8000" 1 "34" 1 3 4
    2 136 2 2 "6000" 4 "34" 1 1 1
    2 1536 2 3 "8000" 1 "34" 1 3 2
    2 924 2 2 "8000" 1 "34" 2 1 3
    3 1536 2 3 "8000" 1 "34" 2 4 3
    1 1536 2 2 "8000" 4 "34" 2 1 4
    1 1536 2 2 "8000" 1 "34" 1 3 2
    2 1536 2 4 "8000" 1 "6" 1 4 3
    2 1512 2 3 "8000" 3 "35" 2 3 4
    2 1536 2 3 "8000" 1 "34" 4 2 4
    2 1602 2 3 "8000" 1 "34" 1 4 4
    2 299 2 2 "8000" 4 "34" 2 3 3
    2 1526 2 2 "8000" 1 "12,26,40,54" 1 3 1
    2 1536 2 2 "8000" 1 "66" 3 3 4
    2 1536 2 2 "8000" 1 "34" 1 3 3
    2 1536 2 2 "8000" 1 "47" 4 3 2
    2 1536 2 2 "8000" 1 "34" 1 1 1
    end
    label values q1 q1
    label def q1 1 "A. 323", modify
    label def q1 2 "B. 3,023", modify
    label def q1 3 "C. 30,023", modify
    label values q3 q3
    label def q3 1 "A", modify
    label def q3 2 "B", modify
    label def q3 3 "C", modify
    label def q3 4 "D", modify
    label values q4 q4
    label def q4 1 "A. Box 1", modify
    label def q4 2 "B. Box 2", modify
    label def q4 3 "C. Box 3", modify
    label def q4 4 "D. Box 4", modify
    label values q6 q6
    label def q6 1 "A. 6", modify
    label def q6 2 "B. 8", modify
    label def q6 3 "C. 10", modify
    label def q6 4 "D. 12", modify
    label values q8 q8
    label def q8 1 "A. 3:15", modify
    label def q8 2 "B. 3:45", modify
    label def q8 3 "C. 9:00", modify
    label def q8 4 "D. 9:45", modify
    label values q10 q10
    label def q10 1 "A. 2708", modify
    label def q10 2 "B. 4733", modify
    label def q10 3 "C. 8726", modify
    label def q10 4 "D. 9718", modify
    label values q11 q11
    label def q11 1 "A. 1.06 zeds", modify
    label def q11 2 "B. 1.16 zeds", modify
    label def q11 3 "C. 5.06 zeds", modify
    label def q11 4 "D. 5.16 zeds", modify
    [/CODE]
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 496 observations
    Use the count() option to list more

    .

  • #2
    I am confused by what you have shown. You speak of merging two data sets, but you show only one. It isn't clear from your description what might be in the unshown data set, nor which data set is master and which is using when you do the -merge-.

    If the two data sets have the variables with the same names, and if those pairs of variables are value labeled with the same labels attached to the same values, the only difference being that the label names are different in the two data sets, then you just need to pick one of the data sets, open it, and use -label rename- to change the names of the value labels in that one to the corresponding names in the other, save it, and then run the -merge-. See -help label rename-.

    If the problem is something other than that, I think you will have to provide example data from the other data set and indicate both how you want to -merge- them, and what you want the resulting merged data set to look like.

    Comment


    • #3
      I did that but i lose the value label when I rename the label. Here is the other data set. You will see that the lab value names are the same. I want tochange the lab value name for either of these data set so when i merge these two I retain both the lab.

      clear
      input str8 q1 byte(q2 q3 q4) str3(q5 q6) byte(q7 q8 q9)
      "q1__.jpg" 3 2 3 "41" "40" 4 2 4
      "q1__.jpg" 3 2 3 "41" "40" 4 3 4
      "q1__.jpg" 3 2 3 "19" "60" 4 3 4
      "q1__.jpg" 3 2 3 "41" "40" 4 3 4
      "q1__.jpg" 3 3 3 "11" "60" 4 3 3
      "q1__.jpg" 2 1 3 "27" "140" 4 3 1
      "q1__.jpg" 4 2 3 "41" "20" 4 3 4
      "q1__.jpg" 4 2 3 "44" "40" 2 2 2
      "q1__.jpg" 3 2 3 "41" "80" 4 3 4
      "q1__.jpg" 3 2 3 "41" "40" 1 2 1
      "q1__.jpg" 3 3 3 "39" "60" 1 2 4
      "q1__.jpg" 3 2 3 "41" "60" 4 2 4
      "" 3 3 1 "" "40" . 3 2
      "q1__.jpg" 3 2 3 "41" "40" 4 2 4
      "q1__.jpg" 3 3 3 "41" "40" 4 3 1
      "q1__.jpg" 3 2 3 "41" "40" 4 2 4
      "q1__.jpg" 3 2 3 "41" "40" 4 2 4
      "q1__.jpg" 3 3 3 "14" "40" 1 3 4
      "q1__.jpg" 3 3 4 "41" "40" 4 2 1
      "q1__.jpg" 3 3 3 "41" "30" 4 2 4
      "q1__.jpg" 3 2 3 "41" "40" 4 2 2
      "q1__.jpg" 3 3 3 "41" "35" 4 2 4
      "q1__.jpg" 3 2 3 "41" "40" 1 2 4
      "q1__.jpg" 4 2 3 "41" "40" 4 1 3
      "q1__.jpg" 3 3 3 "2" "60" 4 3 2
      "q1__.jpg" 3 2 1 "41" "40" 4 2 2
      "q1__.jpg" 3 3 3 "41" "40" 4 3 1
      "q1__.jpg" 3 2 3 "41" "60" 4 3 4
      "q1__.jpg" 3 3 3 "41" "40" 4 3 3
      "q1__.jpg" 3 2 3 "116" "40" 4 3 4
      "q1__.jpg" 3 3 2 "41" "40" 4 2 4
      "q1__.jpg" 3 2 3 "41" "40" 4 3 3
      "q1__.jpg" 3 3 3 "41" "40" 4 3 4
      "q1__.jpg" 3 1 3 "41" "40" 4 3 4
      "q1__.jpg" 3 2 3 "41" "40" 4 2 4
      "q1__.jpg" 3 2 4 "41" "40" 4 3 3
      "q1__.jpg" 4 3 3 "5" "45" 4 3 3
      "q1__.jpg" 3 2 3 "41" "40" 4 2 2
      "q1__.jpg" 3 3 3 "41" "40" 2 3 4
      "q1__.jpg" 3 2 3 "41" "45" 4 2 4
      "q1__.jpg" 4 3 3 "75" "40" 2 3 2
      "q1__.jpg" 3 2 3 "41" "80" 4 3 4
      "q1__.jpg" 3 2 3 "41" "50" 4 3 4
      "q1__.jpg" 3 2 3 "41" "40" 4 2 4
      "q1__.jpg" 3 3 3 "41" "40" 4 3 4
      "q1__.jpg" 3 3 3 "41" "40" 4 2 4
      "q1__.jpg" 3 3 1 "3" "80" 1 3 4
      "q1__.jpg" 3 2 3 "41" "40" 4 3 3
      "q1__.jpg" 3 3 4 "41" "40" 3 1 4
      "q1__.jpg" 3 2 3 "29" "40" 1 3 2
      end
      label values q2 q2
      label def q2 2 "B. 0.43", modify
      label def q2 3 "C. 0.74", modify
      label def q2 4 "D. 0.79", modify
      label values q3 q3
      label def q3 1 "A. 𝑃", modify
      label def q3 2 "B. 𝑆", modify
      label def q3 3 "C. 𝑇", modify
      label values q4 q4
      label def q4 1 "A. 2𝑙 + 2𝑀", modify
      label def q4 2 "B. 𝐴 = 2𝑙 + 2𝑀", modify
      label def q4 3 "C. 𝐴 = 2𝑙𝑀", modify
      label def q4 4 "D. 𝐴 = 4𝑙𝑀", modify
      label values q7 q7
      label def q7 1 "A. Red is more likely on Ben’s spinner than on Rita’s", modify
      label def q7 2 "B. Red is more likely on Rita’s spinner than on Ben’s", modify
      label def q7 3 "C. Red is impossible on both spinners", modify
      label def q7 4 "D. Red is equally likely on both spinners", modify
      label values q8 q8
      label def q8 1 "Tom spent more money for shoes", modify
      label def q8 2 "Peter spent more money for shoes", modify
      label def q8 3 "They both spent the same amount for shoes", modify
      label values q9 q9
      label def q9 1 "A. 𝑦 = π‘₯! + 3", modify
      label def q9 2 "B. 𝑦 = 3π‘₯ + 1", modify
      label def q9 3 "C. 𝑦 = 3π‘₯! βˆ’ 1", modify
      label def q9 4 "D. 𝑦 = π‘₯ + 3", modify
      [/CODE]
      ------------------ copy up to and including the previous line ------------------

      Listed 50 out of 50 observations

      .


      Comment


      • #4
        If I understand what you are asking for, it simply can't be done, and it doesn't make any sense to try.

        Let's just look at q3. In the first data set, we have
        Code:
        label values q3 q3
        label def q3 1 "A", modify
        label def q3 2 "B", modify
        label def q3 3 "C", modify
        label def q3 4 "D", modify
        and in the second, for the "same" variable q3 we find
        Code:
        label values q3 q3
        label def q3 1 "A. 𝑃", modify
        label def q3 2 "B. 𝑆", modify
        label def q3 3 "C. 𝑇", modify
        So the value labels from the two data sets contradict each other as to what label should be applied to each numeric value. No matter how you try to put this together, you will necessarily have to mislabel some of the observations.

        I should also point out that it is unusual to -merge- together two data sets that have a large number of variables in common. That is mostly done when the using data set contains updated information about the values of those variables, and in that case one uses the -update- or -update replace- options to ensure that the values from the using data set, not the master data set, are retained in the result. Even in that situation, however, Stata retains the value labels from the master data set, and will use the value label in the using data set only if the variable is unlabeled in the master.

        Following up on that thought, it appears to me that perhaps you don't want to -merge- these data sets at all. Perhaps you meant -append-? Even if you did, however, you will still into the problem that you have conflicting value labels and only one can prevail.

        Comment

        Working...
        X