Announcement

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

  • reshape by saving variables names

    Hello everyone,

    Could you please help me with this ?

    I am trying to reshape this data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str4 year str2(month day) float(date dow) double bal float(rev exp exp_gen bal_gen rev_yy)
    "2014" "01" "09" 132 4 22.79101800002 . .00672 0 . .
    end
    I woul like to keep these variables : year month day date dow, create a new variable named series, containing the variables names :bal rev exp exp_gen bal_gen rev_yy and a variable for the values of these last variables.

    Thank you

  • #2
    There is no obvious gain to reshaping this dataset. Why do you think you need a different structure?

    Comment


    • #3
      Because it makes it easier to process it in Excel

      Comment


      • #4
        https://www.youtube.com/watch?v=P5y6C-v5-j0

        Comment


        • #5
          Starting with the sample data you provided (thanks for using dataex!) here is some technique to start you on your way.
          Code:
          . rename (bal rev exp exp_gen bal_gen rev_yy) var_=
          
          . generate long id = _n
          
          . reshape long var_, i(id) j(variable) string
          (note: j = bal bal_gen exp exp_gen rev rev_yy)
          
          Data                               wide   ->   long
          -----------------------------------------------------------------------------
          Number of obs.                        1   ->       6
          Number of variables                  12   ->       8
          j variable (6 values)                     ->   variable
          xij variables:
               var_bal var_bal_gen ... var_rev_yy   ->   var_
          -----------------------------------------------------------------------------
          
          . rename var_ value
          
          . list, clean 
          
                 id   variable   year   month   day   date   dow      value  
            1.    1        bal   2014      01    09    132     4   22.79102  
            2.    1    bal_gen   2014      01    09    132     4          .  
            3.    1        exp   2014      01    09    132     4     .00672  
            4.    1    exp_gen   2014      01    09    132     4          0  
            5.    1        rev   2014      01    09    132     4          .  
            6.    1     rev_yy   2014      01    09    132     4          .  
          
          .

          Comment


          • #6
            This is great, thank you William !!
            Nice one Nick :D

            Comment

            Working...
            X