Announcement

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

  • reshape or what?

    Dear All, I found this question here (http://bbs.pinggu.org/thread-6513949-1-1.html). The data is
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int id str10 date float vol
     22 "2016-03-21" .052813
     22 "2016-03-22" .052454
     22 "2016-03-23" .052408
     22 "2016-03-24" .047639
    153 "2016-03-22" .050336
    153 "2016-03-23" .050088
    153 "2016-03-24" .043589
    153 "2016-03-25" .042855
    521 "2016-03-20" .037602
    521 "2016-03-21"  .03761
    521 "2016-03-22" .037194
    521 "2016-03-23"     .03
    end
    and the purpose to transform the data to be something like
    Code:
    input int id22 str10 date22 float vol22 int id153 str10 date153 float vol153 int id521 str10 date521 float vol521
      .  ""            .       .  ""  .                   521 "2016-03-20" .037602
     22 "2016-03-21" .052813   .  ""  .                   521 "2016-03-21"  .03761
     22 "2016-03-22" .052454   153 "2016-03-22" .050336   521 "2016-03-22" .037194
     22 "2016-03-23" .052408   153 "2016-03-23" .050088   521 "2016-03-23"     .03
     22 "2016-03-24" .047639   153 "2016-03-24" .043589   .  ""  .
     .  ""  .                  153 "2016-03-25" .042855   .  ""  .
    end
    Basically, the data one the same date should be on the same row! Any suggestion is appreciated.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    Bad idea. The present data layout (structure, format) is fine for the great majority of Stata purposes.

    If one did reshape, you certainly wouldn't need the same dates again and again in two or more variables.

    Sorry, I can't read the original, but perhaps you can tell us if there was a specific reason given for wanting this.

    String dates need to be fixed for most Stata purposes.

    Comment


    • #3
      Dear Nick, I share with your concern. However, it seems to me the question asker (for unknown reasons) wants to regress vol22 on vol153 and vol521.
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment


      • #4
        OK. So the reshape is one line, left as an exercise to the reader.

        Comment


        • #5
          Dear Nick, Thanks, but it is not that straightforward to me (I must miss something!).
          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment


          • #6
            Code:
            . reshape wide vol, i(date) j(id)
            (note: j = 22 153 521)
            
            Data                               long   ->   wide
            -----------------------------------------------------------------------------
            Number of obs.                       12   ->       6
            Number of variables                   3   ->       4
            j variable (3 values)                id   ->   (dropped)
            xij variables:
                                                vol   ->   vol22 vol153 vol521
            -----------------------------------------------------------------------------
            
            . list, clean noobs
            
                      date     vol22    vol153    vol521  
                2016-03-20         .         .   .037602  
                2016-03-21   .052813         .    .03761  
                2016-03-22   .052454   .050336   .037194  
                2016-03-23   .052408   .050088       .03  
                2016-03-24   .047639   .043589         .  
                2016-03-25         .   .042855         .

            Comment


            • #7
              Dear William, Thank you so much.
              Ho-Chuan (River) Huang
              Stata 17.0, MP(4)

              Comment

              Working...
              X