Announcement

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

  • Reshape time series data

    Hi, everyone. I have more than 1,000 stock with 5 years price data. A very simple example as shown below. Basically, the date is the time line. The name of the 3 other variables represents the name of the stock.

    Click image for larger version

Name:	sfssd.PNG
Views:	1
Size:	9.2 KB
ID:	1687616



    I would like to reshape the data as time series format as shown below. Could anyone please help me out? Thank you very much in advance.

    Click image for larger version

Name:	sdfsdsds.PNG
Views:	1
Size:	24.9 KB
ID:	1687617



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 date str7 DS2653 str6 DX1122 str5 SD3435
    "01.01.2014" "5"  "1" "1" 
    "02.01.2014" "6"  "2" "2" 
    "03.01.2014" "7"  "4" "2" 
    "06.01.2014" "4"  "5" "3" 
    "07.01.2014" "6"  "4" "5" 
    "08.01.2014" "3"  "3" "3" 
    "09.01.2014" "22" "2" "1" 
    "10.01.2014" "2"  "2" "3" 
    "13.01.2014" "2"  "4" "2" 
    "14.01.2014" "22" "3" "3" 
    "15.01.2014" "2"  "4" "7" 
    "16.01.2014" "3"  "3" "5" 
    "17.01.2014" "2"  "2" "6" 
    "20.01.2014" "1"  "3" "10"
    end




  • #2
    Code:
    rename (DS2653-SD3435) price=
    reshape long price, i(date) j(stock_name) string

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Code:
      rename (DS2653-SD3435) price=
      reshape long price, i(date) j(stock_name) string
      Amazing. Thank you.

      Comment

      Working...
      X