I am working with a dataset which contains daily stock prices of over 300 stocks. Each stock is named s_nameofthebusiness.
The next step is to create daily returns for each of this stocks as a new variable. Unfortunately I do not have experience in programming loops or working with macros yet.
In general the return is generated with f.e gen r_bmw= ((s_bmw-L.s_bmw)/L.s_bmw)*100(to get it in %). To adress all stocks I will Need a macro with s_* as far as I know.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id date) double(s_zions s_xerox s_whirl s_weyer) 1 0 3.4687 25.1359 33 11.3059 2 1 3.5 25.3554 32.25 11.6129 3 2 3.5625 25.575 32.375 11.3571 4 3 3.5625 25.6298 32.75 11.2548 5 4 3.625 25.6847 31.75 11.2036 6 5 3.5625 25.5201 32.25 11.2036 7 6 3.625 25.1359 32.25 10.999 8 7 3.625 24.9164 32.375 11.1013 9 8 3.625 24.9713 33.5 11.0501 10 9 3.5 24.5871 31.5 10.7432 end format %td date
Thank you.
0 Response to Generating new variables out of existing ones using a loop
Post a Comment