Announcement

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

  • Equivalent of R's spread in Stata?

    Hello, i have data where variables are spread across rows for a given observation that I wanted to transform to columns of which there are corresponding values, and I was wondering if there was an equivalent to R's spread in stata to do so?

  • #2
    R experts here do exist but are not thick in the ground, so unless one of them pipes up you may need to tell us much more.

    Perhaps you mean reshape

    Comment


    • #3
      Sorry, i apologize

      I have data like this:


      Year Team Position AV
      2008 ARI wr 5
      2008 ARI te 7
      2008 ARI cb 3
      2008 ARI s 2

      And I want to shape the data as

      Year Team wr te cb s
      2008 ARI 5 7 3 2

      Comment


      • #4
        Yes, that's a reshape. Did you try it?

        Code:
        clear 
        input Year str3 Team str2 Position AV
        2008 ARI wr 5
        2008 ARI te 7
        2008 ARI cb 3
        2008 ARI s 2
        end 
        
        reshape wide AV, i(Year Team) j(Position) string 
        renpfix AV 
        
        list 
        
             +--------------------------------+
             | Year   Team   cb   s   te   wr |
             |--------------------------------|
          1. | 2008    ARI    3   2    7    5 |
             +--------------------------------+
        Please do review the FAQ Advice http://www.statalist.org/forums/help especially #12.

        Comment


        • #5
          I will only add to Nick's answer a question: why do you want to do this? Most data analysis in Stata is easier when the data is in the original long layout, and becomes more difficult or impossible in the wide layout you plan to create. There are a few exceptions, and it is also possible that you don't plan to analyze this data so much as to copy it into a spreadsheet for human eyes to read. But before doing this, consider whether it really is something you will benefit from doing, because usually, in Stata, it is not.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            Yes, that's a reshape. Did you try it?

            Code:
            clear
            input Year str3 Team str2 Position AV
            2008 ARI wr 5
            2008 ARI te 7
            2008 ARI cb 3
            2008 ARI s 2
            end
            
            reshape wide AV, i(Year Team) j(Position) string
            renpfix AV
            
            list
            
            +--------------------------------+
            | Year Team cb s te wr |
            |--------------------------------|
            1. | 2008 ARI 3 2 7 5 |
            +--------------------------------+
            Please do review the FAQ Advice http://www.statalist.org/forums/help especially #12.
            Awesome, I will try it.

            Originally posted by Clyde Schechter View Post
            I will only add to Nick's answer a question: why do you want to do this? Most data analysis in Stata is easier when the data is in the original long layout, and becomes more difficult or impossible in the wide layout you plan to create. There are a few exceptions, and it is also possible that you don't plan to analyze this data so much as to copy it into a spreadsheet for human eyes to read. But before doing this, consider whether it really is something you will benefit from doing, because usually, in Stata, it is not.
            It's for a specific model that I'm running based on a team

            Comment

            Working...
            X