I have the raw data as follows:
Code:
input str10 A str17(IM IP) "Code" "DISA.SI(RI)~U$" "SUNR.SI(RI)~U$" " 1/1/1998" "20.29" "47.43" " 1/8/1998" "17.06" "28.04" " 1/15/1998" "15.81" "42.54" " 1/22/1998" "15.82" "42.56" " 1/29/1998" "16.15" "43.44" " 2/5/1998" "24.41" "45.14" " 2/12/1998" "23.77" "63.54" " 2/19/1998" "22.6" "64.55" " 2/26/1998" "26.52" "64.63" " 3/5/1998" "21.5" "63.61" " 3/12/1998" "21.09" "64.70999999999999" " 3/19/1998" "22.07" "65.3" " 3/26/1998" "23.01" "62.59" " 4/2/1998" "18.72" "61.53" " 4/9/1998" "18.3" "39.24" " 4/16/1998" "16.59" "65.44" " 4/23/1998" "16.73" "50.3" " 4/30/1998" "16.79" "50.47" " 5/7/1998" "14.8" "38.41" " 5/14/1998" "13.76" "48.24" " 5/21/1998" "15.49" "48.88" " 5/28/1998" "12.1" "41.76" " 6/4/1998" "11.26" "42.94" " 6/11/1998" "10.18" "35.84" " 6/18/1998" "11.38" "37.41" " 6/25/1998" "10.65" "36.75" " 7/2/1998" "9.66" "47.02" " 7/9/1998" "10.32" "43.63" " 7/16/1998" "9.060000000000001" "40.04" " 7/23/1998" "8.140000000000001" "42.27" " 7/30/1998" "7.37" "42.1" " 8/6/1998" "8" "41.55" " 8/13/1998" "7.25" "37" " 8/20/1998" "7.98" "36.99" " 8/27/1998" "7.88" "36.52" " 9/3/1998" "7.94" "35.34" " 9/10/1998" "8.050000000000001" "35.83" " 9/17/1998" "8.82" "36" " 9/24/1998" "7.37" "39.1" " 10/1/1998" "7.5" "39.78" " 10/8/1998" "6.91" "35.27" "10/15/1998" "8.66" "40.14" "10/22/1998" "9.380000000000001" "40.67" "10/29/1998" "11.73" "37.49" " 11/5/1998" "12.5" "47.83" "11/12/1998" "10.69" "51.39" "11/19/1998" "11.71" "54.14" "11/26/1998" "11.5" "53.21" " 12/3/1998" "10.78" "56.54" "12/10/1998" "11.66" "57.1" "12/17/1998" "11.58" "44.11" "12/24/1998" "10.77" "43.94" "12/31/1998" "10.74" "43.84" " 1/7/1999" "11.37" "43.29" " 1/14/1999" "13.56" "54.56" " 1/21/1999" "13.64" "47.16" " 1/28/1999" "11.98" "45.85" " 2/4/1999" "12" "39.04" " 2/11/1999" "12" "42.86" " 2/18/1999" "13.4" "42.54" " 2/25/1999" "12.47" "37.43" " 3/4/1999" "13.13" "37.21" " 3/11/1999" "13.13" "37.2" " 3/18/1999" "12.47" "37.42" " 3/25/1999" "13.93" "41.89" " 4/1/1999" "13.19" "37.37" " 4/8/1999" "14.64" "41.82" " 4/15/1999" "14.96" "55.7" " 4/22/1999" "22.97" "55.95" " 4/29/1999" "20.15" "51.78" " 5/6/1999" "23.08" "53.94" " 5/13/1999" "22.27" "46.95" " 5/20/1999" "22.81" "52.55" " 5/27/1999" "26.33" "74.63" " 6/3/1999" "30.08" "79.34" " 6/10/1999" "35.43" "78.33" " 6/17/1999" "55.08" "83.54000000000001" " 6/24/1999" "62.5" "91.84999999999999" " 7/1/1999" "72.31999999999999" "108.02" " 7/8/1999" "55.18" "81.41" " 7/15/1999" "44.74" "57.82" " 7/22/1999" "41.01" "56.3" " 7/29/1999" "42.76" "59.69" " 8/5/1999" "39.35" "55.59" " 8/12/1999" "34.06" "52.51" " 8/19/1999" "36.99" "55.45" " 8/26/1999" "47.15" "65.67" " 9/2/1999" "42.84" "56.74" " 9/9/1999" "42.77" "58.18" " 9/16/1999" "41.89" "58" " 9/23/1999" "41.37" "54.27" " 9/30/1999" "37.23" "53.18" " 10/7/1999" "40.71" "55.38" "10/14/1999" "39.97" "53.86" "10/21/1999" "37.92" "51.07" "10/28/1999" "36.45" "50.36" " 11/4/1999" "40.27" "55.82" "11/11/1999" "46.1" "60.92" "11/18/1999" "45.49" "59.56" end
e raw date is exported from Datastream in a form of row, the first column is Date, the sencond column is stock price of firm 1, the thirst column is for firm 2 and so on.....
I need to format the raw data. In details, I need to transpose the panel data to the form that all firms are in one column, and then the next column is Date. But I do not know how to do. Could you please help?
Mr @Cylde gave me the code in previous topic like this
Mr @Cylde gave me the code in previous topic like this
rename A str_date
foreach v of varlist IM-IP {
rename `v' price_`=strtoname(`v'[1])'
}
drop in 1
destring price_*, replace
gen date = daily(str_date, "MDY")
assert missing(date) == missing(str_date)
format date %td
drop str_date
reshape long price_, i(date) j(firm) string
rename price_ price
foreach v of varlist IM-IP {
rename `v' price_`=strtoname(`v'[1])'
}
drop in 1
destring price_*, replace
gen date = daily(str_date, "MDY")
assert missing(date) == missing(str_date)
format date %td
drop str_date
reshape long price_, i(date) j(firm) string
rename price_ price
Here is my results,
Code:
foreach v of varlist B-ADE{ 2. rename `v' price_`=strtoname(`v'[1]0)' 3. } B ambiguous abbreviation r(111);
I look forward to hearing from you.
Thank you very much in advance.
Regards,
Celine
0 Response to How to reshape the panel data rows to columns
Post a Comment