Announcement

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

  • Convert datastream wide data to long format

    Hi guys, i have attached a sample excel file with data as it would appear downloaded from Datastream. I would like to know how to change it from wide format to long format. FYI i have about 1000 companies in one worksheet
    Click image for larger version

Name:	returns.JPG
Views:	1
Size:	280.4 KB
ID:	1551074
    .
    Attached Files

  • #2
    Next time post a sample of your data using dataex (see the FAQ for instructions).

    Code:
    import excel "Returns.xlsx", sheet("Sheet2") cellrange(A4) clear
    
    ren A name 
    ds name, not
    ren (`r(varlist)') (v#), addnumber
    
    tempfile temp 
    
    preserve 
    keep in 1 
    reshape long v, i(name) j(var)string 
    ren v title 
    save `temp'
    restore 
    
    drop in 1
    
    reshape long v, i(name) j(var)string
    merge m:1 var using `temp', keep(match) nogen 
    drop if inlist(lower(name), "currency", "code") 
    
    gen date = date(name, "MDY")
    format date %td 
    drop var name 
    
    destring v, replace


    Comment


    • #3
      Thank you Justin. You have been so helpful and thanks for the "dataex tip"

      Comment

      Working...
      X