Announcement

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

  • Reshape long 1 row dataset with no identifier

    Hi,

    I am trying to reshape long the following dataset:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(r_EPS r_DGRO r_MGK sd_EPS sd_DGRO sd_MGK SR_EPS SR_DGRO SR_MGK)
    .0020684573341622657 .002197724135520811 .0033902101308780743 .025480517579479105 .024766451760310653 .025364229984079965 .08117799521576873 .088737949093005 .1336610704526005
    end
    I would like to r_ , sd_ and SR_ as variables and 1 additional variable called "ETF". I have tried this but it is not the right syntax:
    Code:
    reshape long r_ sd_ SR_
    Please help. Thanks.


  • #2
    Do you want this?
    Code:
    . gen id = 1
    
    . reshape long r_ sd_ SR_, i(id) j(etf) string
    (note: j = DGRO EPS MGK)
    
    Data                               wide   ->   long
    -----------------------------------------------------------------------------
    Number of obs.                        1   ->       3
    Number of variables                  10   ->       5
    j variable (3 values)                     ->   etf
    xij variables:
                         r_DGRO r_EPS r_MGK   ->   r_
                      sd_DGRO sd_EPS sd_MGK   ->   sd_
                      SR_DGRO SR_EPS SR_MGK   ->   SR_
    -----------------------------------------------------------------------------
    
    . list, sep(0)
    
         +-----------------------------------------------+
         | id    etf          r_         sd_         SR_ |
         |-----------------------------------------------|
      1. |  1   DGRO   .00219772   .02476645   .08873795 |
      2. |  1    EPS   .00206846   .02548052     .081178 |
      3. |  1    MGK   .00339021   .02536423   .13366107 |
         +-----------------------------------------------+

    Comment


    • #3
      That's exactly what I want. Thanks a lot Joro!

      Comment


      • #4
        Here is some advice from the manual entry for reshape amplifying the helpful technique of Joro Kolev.


        If your data are in wide form and you do not have a group identifier variable (the i(varlist)
        required option), you can create one easily by using generate; see [D] generate. For instance, in
        the last example, if we did not have the id variable in our dataset, we could have created it by typing

        . generate id = _n

        Comment

        Working...
        X