Announcement

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

  • Stata changes labels of dataset when reshaping

    Hi everyone,

    When I reshape my datataset from wide to long format, the labels in the long format are suddenly those from a different dataset that has the same variable names and not the labels from the dataset in the wide format I actually reshaped.

    Has someone any explanation why this could happen?

    Many thanks and greetings,
    Kathrin




  • #2
    Welcome to the Stata Forum / Statalist.

    I hope this FAQ will be helpful to you.
    Best regards,

    Marcos

    Comment


    • #3
      Well, in general, when you -reshape long-, the variables being "lengthened" can, and often do, all have different variable labels. But they are being combined into a single variable. So how is Stata supposed to reconcile the differing variable labels? It simply drops them and leaves the combined variable unlabeled. For value labels, Stata picks the value label attached to the last of the series See this example

      Code:
      use http://www.stata-press.com/data/r15/reshape1, clear
      label define ue80 0 "no"    1    "yes"
      label define ue81 0 "nyet"    1    "da"
      label define ue82 0 "ie"    1    "hai"
      
      foreach v of varlist ue* {
          label values `v' `v'
      }
      
      forvalues i = 80/82 {
          label var inc`i' "Inc in 19`i'"
      }
      
      
      des
      list, noobs clean
      
      reshape long inc ue, i(id) j(year)
      des
      But you seem to be describing something rather different whereby Stata is in fact creating new variable labels that are attached to some other data set. I have never heard of that before and I have difficulty imagining how that would happen. I think it might help if you showed an example of the data set as it looked before reshaping, the exact code you used to -reshape- it, and an example of the data set as it looked after reshaping. Be sure to use -dataex- to show the data examples so that no details are left out or changed. (-ssc install dataex- to get it, and -help dataex- to read the simple instructions for using it.)

      Comment


      • #4
        Clyde writes

        I have never heard of that before
        which is also my experience. He continues

        and I have difficulty imagining how that would happen
        My imagination is working overtime, and I imagine that the second dataset from which the labels were supposedly copied was itself also created using reshape long, and the original labels in that second dataset (those prior to the reshape long) were changed by reshape long in exactly the same way as the labels in the current dataset.

        Comment

        Working...
        X