Announcement

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

  • "reshape" wide to long for unordered variables

    Hello,

    Is there a command to "reshape" wide to long for unordered variables?
    Here's what my data looks like:



    date ACN ATVI ACM AER
    1/3/2022 407.21 67.42 77.35 67.7
    1/4/2022 404.3 67.2 77.87 68
    1/5/2022 397.18 66.29 75.8 65.59
    1/6/2022 378 63.82 75.77 66.78
    1/7/2022 370.75 64.04 74.49 67.72
    1/10/2022 373 63.11 74.22 67.35
    1/11/2022 375.11 65.85 75.15 67.17
    1/12/2022 377.19 64.81 74.69 66.48


    Thank you.

  • #2
    Well, you can do this:
    Code:
    rename (acn-aer) value=
    reshape long value, i(date) j(index) string
    Whether this is a meaningful thing to do depends on what these variables ACN, ATVI, ACM, and AER are. It is also conceivable that these variable names are initialisms for something and that the A is, by itself meaningful. In that case, one might skip the renaming and just do
    Code:
    reshape long a, i(date) j(index) string
    Again, not knowing what these variables are, I have no idea whether this organization of the data is meaningful or useful.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thank you. I don't think I can use rename because then the original names would be lost. The names are ticker symbols (here, first 4 of several hundred) of companies. In other words, they are company nicknames. There is nothing special about the letter A; they go alphabetically from A to Z.
      Is there a way to do this without losing the ticker symbols?

      Comment


      • #4
        I don't think I can use rename because then the original names would be lost.
        No, the original names will not be lost. Try at and you will see.

        Comment


        • #5
          It worked! Thank you very much!

          Comment

          Working...
          X