Announcement

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

  • Reshape to retain variable names?

    Can you please advise on the reshape method? I have used the one that is accessible through the Data:Create or Change Data... to move from wide to long but it does not retain the name of the variables. Basically, the variables (columns) I use are "mydate" and then "fund1" "fund2" and so on until "fund3000". When I reshape I get the column with a number instead of fund1, fund2 and so on. Can you advise how to reshape them so they retain the fund name? Thanks, West.
    Last edited by West Ray; 12 Nov 2018, 13:35. Reason: forgot abt tags

  • #2
    The number in your column is simply the number following "fund" in the variable name.
    For instance, the fund200 value ends up on the line with the value 200.

    If you want the variable name, just do gen varname="fund"+string(j) where j stands for the variable that holds those numbers.

    Reproducible example:

    Code:
    clear
    set obs 10
    forv i=1/20 {
        gen fund`i'=runiform()
    }
    gen i=_n
    reshape long fund, i(i) j(j)
    
    gen varname="fund"+string(j)

    Comment


    • #3
      Dear Jean,

      Thanks, it worked perfectly (this bit):
      gen varname="fund"+string(j)
      Regards
      West

      Comment

      Working...
      X