Announcement

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

  • Merge data in the same dataset

    I am trying to merge data for different variables in the same data set, e.g. combine var1 var2 var3 to become one column of data. I tried append but doesn't work. Thanks!

  • #2
    Your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared. Please help us help you. Show example data. Show your code. Show us what Stata told you. Tell us what precisely is wrong. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output.

    Perhaps what you need is to reshape your data into a long layout. The output of
    Code:
    help reshape
    will describe this, but better still click the link to the full PDF documentation found at the top of the help output and read the full documentation, because reshaping data is one of the most useful data management tools in Stata, but also is a bit hard to grasp.

    Comment


    • #3
      I share William Lisowski's uncertainty about what you want, but I'll offer a guess about a command with the idea that, if you read the relevant documentation, it might help you in describing what you want: Take a look at -help stack-, which would fit with desire to combine several variables into one variable ("column"). However, needing to do this is unusual, so I wouldn't be sure that this is actually what you want.

      Comment


      • #4
        In data management the words "merge" and "append" have special meaning.

        "merge" means connecting two data sets by adding new columns, the cases are often matched by some identifier. For example, there is data set with client's name and address, and there is a data set with client's name and purchase record. We would like to combine them into a wider data set with client names, address, and purchase record.

        "append" means connecting two data sets by adding new rows. For instance, we have weather data of 2020 (366 cases), and we have the same set of variables for 2021 (365 cases), and we'd like combing them into a longer data set with 731 cases.

        In post #1 it was mentioned that all the variables are already in the same file, so my guess it is not about merge or append. Given that you previously asked about trimming a string variable, are you trying to combine to string variables together? Such as combining "first name" and "last name" into a "full name"?

        Comment


        • #5
          hi all, thanks for the suggestion, I used "stack" command to merge and created a new variable "into" (new_var)

          Comment

          Working...
          X