Announcement

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

  • How to rearrange data? row to column & new variables &column to an extend of column

    Treatment Subject Round1max Round2 Round3 Round4 Round5 Round6
    0 101 1 1 1 1 1 1
    0 103 0 0 0 1 0 1
    0 104 1 0 0 1 0 1
    0 105 1 1 1 1 0 1
    0 106 1 1 1 1 1 1
    Here is my data with columns: Treatment, Subject and Six Rounds results.
    How could I change the data to (for example for subject 101 & 103):
    Subject Rounds Results
    101 1 1
    101 2 1
    101 3 1
    101 4 1
    101 5 1
    101 6 1
    103 1 0
    103 2 0
    103 3 0
    103 4 1
    103 5 0
    103 6 1
    From row to column, I can do a transpose of matrix but how about others?
    Thanks

  • #2
    Good opportunity to tryout the new forum

    Code:
    clear
    input Treatment    Subject    Round1max    Round2    Round3    Round4    Round5    Round6
    0    101    1    1    1    1    1    1
    0    103    0    0    0    1    0    1
    0    104    1    0    0    1    0    1
    0    105    1    1    1    1    0    1
    0    106    1    1    1    1    1    1
    end
    
    rename Round1max Round1
    rename (Round*) (Result*)
    reshape long Result, i(Subject) j(Round)
    list
    010100100110111101101110011011100110100101100101

    Comment


    • #3
      that's really works!! thanks a lot!!!!

      Comment


      • #4
        Hello,
        do you think it is possible to re-arrange from a situation like this
        var1year1 var1year2 var2 year1 var2 year2
        a 1 2 3 4
        b 5 6 7 8
        c 9 10 11 12
        to a situation like this
        year1 year2
        a
        var1 1 2
        var2 3 4
        b
        var1 5 6
        var2 7 8
        c
        var1 9 10
        var2 11 12

        Or what is the best way to arrange the first table for dynamic panel data analysis ?
        Thank you very much.

        Comment


        • #5
          Danny,

          Yes, but you will need to switch the names of your variables around:

          Code:
          rename var1year1 year1var1
          rename var1year2 year2var1
          rename var2year1 year1var2
          rename var2year2 year2var2
          gen id=_n   // Or use the variable (if any) that contains a, b, and c as a unique identifier for each subject
          reshape long year1 year2, i(id) j(j) string
          The rename is required so that the stub names in the reshape command (the first part of the variable name) become the near variables (year1 year2) in the long data set.

          If this doesn't work or if your data set has some peculiarities that I haven't dealt with here, you should probably start a new thread so that others can chip in as well.

          Regards,
          Joe

          Comment


          • #6
            Actually, the renames are not necessary.

            Code:
            reshape long @year1 @year2, I(id) j(j) string
            will do the same thing.

            Comment


            • #7
              Thank you very much guys!
              I will try to do it in next days... I will let you now.
              Thanks again.
              Last edited by DannyBulls; 12 May 2014, 04:08.

              Comment


              • #8
                Hello again,
                I tried your command but starting from this
                ID var1year1 var1year2 var2 year1 var2 year2
                a 1 2 3 4
                b 5 6 7 8
                c 9 10 11 12

                and reshaping from wide to long with your command the result is (example with only one variable)

                ID year var1
                a 1 1
                a 2 2
                b 1 5
                b 2 6
                c 1 9
                c 2 10
                Do you know what could be the problem?
                How to have the outcome as in my previos example?
                Thank you again.

                Regrads











                Comment

                Working...
                X