I'm looking for a clean way to convert this data to long-style format, but it's more of a stack/append than a reshape.
The final data should be period, return, mkt (r_GSPC), so I need to stack [period, r_firm, r_GSPC] by firm.
One way is to create individual files for each firm, then stack using append. But I'm curious if there's a more straightforward way.
I've tried stack, but couldn't get it to do what I wanted. I can imagine some other kludgy ways to do it, but curious if there's something really simple I'm missing.
The final data should be period, return, mkt (r_GSPC), so I need to stack [period, r_firm, r_GSPC] by firm.
One way is to create individual files for each firm, then stack using append. But I'm curious if there's a more straightforward way.
I've tried stack, but couldn't get it to do what I wanted. I can imagine some other kludgy ways to do it, but curious if there's something really simple I'm missing.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(period r_AMZN r_GOOG r_T r_AAPL r_TSLA r_GSPC) 21186 . . . . . . 21187 .012694394 .016279915 -.02336369 -.0001746598 -.01028583 .006378433 21188 .004466025 .003614757 .00925308 .0046343626 -.008324531 .004020543 21189 .016033294 .014465924 .003677456 .011321095 .006210416 .007009146 21192 .014321633 .0042640576 .002880042 -.0037213564 .0607547 .0016609638 21193 .004664812 -.000614502 -.002610749 -.00011473173 -.008118245 .0013020835 21194 .0013003597 -.003304841 -.02347964 -.00022931755 .003320894 -.0011128458 21195 .017661398 .002635719 -.0038303896 .005664129 .00936466 .007009026 21196 .022093365 .01502866 .011447542 .010273386 -.005132258 .006726926 21200 -.00026062113 -.000445588 -.004890321 -.005095164 .011356387 -.003530713 end format %td period label var period "Day" label var r_AMZN "AMZN Continuously Compounded Ret" label var r_GOOG "GOOG Continuously Compounded Ret" label var r_T "T Continuously Compounded Ret" label var r_AAPL "AAPL Continuously Compounded Ret" label var r_TSLA "TSLA Continuously Compounded Ret" label var r_GSP "_GSPC Continuously Compounded Ret"
Comment