I am using export excel
in Stata 15.0.
My data consists of 1,815 standardized daily trade summaries, which I currently have in 1,815 different Excel files (see May 16, 2011 example below).Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str58 A str102 B str16 C str8 D str10 E "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "FINRA-INTERACTIVE DATA: Structured Trading Activity Report" "" "" "" "" "" "DATA AS OF:" "16may2011" "" "" "" "" "" "" "" "" "ASSET CLASS" "FNMA" "" "" "" "" "TRADE" "UNIQUE" "$ TRADES" "" "" "COUNT" "SEC ID'S" "(000'S)" "" "AGENCY PASS-THRU (TBA, STIP, $ ROLLS)" "" "" "" "" "SINGLE FAMILY 15Y" "865" "16" "15018790.3" "" "SINGLE FAMILY 30Y" "2374" "23" "58189420.3" "" "OTHER" "*" "*" "*" "" "AGENCY PASS-THRU (SPECIFIED)" "" "" "" "" "SINGLE FAMILY 15Y" "424" "298" "1549436.5" "" "SINGLE FAMILY 30Y" "625" "351" "3383242.5" "" "ADJUSTABLE/HYBRID" "64" "57" "396725.5" "" "OTHER" "0" "0" "0" "" "AGENCY CMO" "" "" "" "" "P&I" "325" "148" "223160.9" "" "IO/PO" "15" "5" "127288.7" "" "" "" "" "" "" "ASSET CLASS" "INVESTMENT GRADE" "" "" "" "" "TRADE" "UNIQUE" "$ TRADES" "" "" "COUNT" "SEC ID'S" "(000'S)" "" "NON-AGENCY CMO" "" "" "" "" "P&I" "274" "112" "55396.6" "" "IO/PO" "0" "0" "0" "" "CMBS" "" "" "" "" "P&I" "108" "78" "493221.9" "" "IO/PO" "61" "11" "5682863.4" "" "ABS" "146" "99" "393618.9" "" "CBO/CDO/CLO" "18" "13" "606495.2" "" "OTHER" "*" "*" "*" "" "" "" "" "" "" "* Indicates trade count is less than 5" "" "" "" "" "† Includes Unrated Securities and Unrated New Issues " "" "" "" "" "Note: Data updated with current day's trades at approximately 8PM New York time" "" "" "" "" "These reports can be found online at http://www.finra.org and http://www.interactivedata.com" "" "" "" "" "For additional information regarding the reports please contact TRACE Data Services at (888) 507-3665." "" "" "" end
Code:
forval x = 1/1815 { clear import excel "$dailysum\FINRA_IDC_STAR-day`x'.xls", /// sheet("TradingActivity") firstrow /*Cleaning the data imported from Excel*/ drop A drop if B == "" local vars C D E F G H I J K L M N foreach y of local vars { replace `y' = "1" if `y' == "*" replace `y' = "1" if `y' == "0" } /*Exporting desired variables from distinct Excel files into single file*/ export excel C using "$dailysum\compilation.xlsx" if /// B == "SINGLE FAMILY 15Y" & B[_n-1] == "AGENCY PASS-THRU (TBA, STIP, $ ROLLS)", /// sheet("FNMA-TradeCount") cell(A`x') sheetmodify nolabel }
file Dropbox\Research_Data\TRACE\Daily Trade Reports - Structured Products\compilation.xlsx saved
(12 observations deleted)
(2 real changes made)
(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)
(1 real change made)
(0 real changes made)
(2 real changes made)
(0 real changes made)
(2 real changes made)
(0 real changes made)
(2 real changes made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(7 real changes made)
(0 real changes made)
(7 real changes made)
(0 real changes made)
(7 real changes made)
file Dropbox\Research_Data\TRACE\Daily Trade Reports - Structured Products\compilation.xlsx saved
(12 observations deleted)
(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)
(1 real change made)
(2 real changes made)
(0 real changes made)
(3 real changes made)
(0 real changes made)
(3 real changes made)
(0 real changes made)
(3 real changes made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(7 real changes made)
(0 real changes made)
(7 real changes made)
(0 real changes made)
(7 real changes made)
file Dropbox\Research_Data\TRACE\Daily Trade Reports - Structured Products\compilation.xlsx could not be saved
Thanks for you help!
Comment