Hi all,
I'm having a problem with reshape that I wish I don't have to deal with manually. I have a dataset of daily (non consecutive) observations for many (I can't currently say the exact number) companies. For each of them I also have their daily stock repurchase quantity and the number of shares. When I reshape long to wide,
I get the error message r(9), which says that there are
observations within i(date) with the same value of j(id). The reason is pretty simple. On one specific date, one company may repurchase only once, while others more than once in a single day.
Below is an example of my dataset
As you can notice, the id "secNXT" has three repurchase transactions on the same day. This is not a problem, since I'm working with daily observations, so that:
1) I can sum up all the transactions (column "amount") in each day;
2) I need only the last observation of each day with multiple transactions for the column "s_o"
3) I need only one obs for the column "px_last", which can be the last, as well as another (as well as the mean).
Apologise if date is in integers.
Any suggestion on how to avoid doing this manually?
Thank You
SG
I'm having a problem with reshape that I wish I don't have to deal with manually. I have a dataset of daily (non consecutive) observations for many (I can't currently say the exact number) companies. For each of them I also have their daily stock repurchase quantity and the number of shares. When I reshape long to wide,
Code:
reshape wide amount s_o px_last, i(date) j(id) string
observations within i(date) with the same value of j(id). The reason is pretty simple. On one specific date, one company may repurchase only once, while others more than once in a single day.
Below is an example of my dataset
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str11 id int date double(amount s_o px_last) "secBP/" 16714 7938000 20965.041 634.5 "secBT/A" 16714 1000000 8450.818 223 "secDGE" 16714 1400000 2938.265 841 "secDXNS" 16714 750000.062 1858.33 106.436 "secHAS" 16714 2000000 1573.364 119.25 "secHNS" 16714 325000.031 728.769 585 "secIMB" 16714 300000.031 715.236 1412.33 "secIMI" 16714 80000.008 347.035 489.429 "secJDW" 16714 1000000 174.481 290 "secNXT" 16714 50000.004 254.797 1360 "secNXT" 16714 191033.016 254.797 1360 "secNXT" 16714 50000.004 254.797 1360 "secPMP" 16714 100000.008 9.901 188.5 "secTNI" 16714 50000.004 289.311 588.5 "secULVR" 16714 423410.031 2885.778 1316.667 "secVOD" 16714 17500000 62976 214.651 "secWMH" 16714 750000.062 387.766 381.485 "secABP" 16715 50000.004 305.977 523 "secAIE" 16715 37702.004 348.541 67.219 "secBP/" 16715 6808000 20965.041 620.5 "secBT/A" 16715 1000000 8450.818 219.5 end format %tdDD/NN/CCYY date
1) I can sum up all the transactions (column "amount") in each day;
2) I need only the last observation of each day with multiple transactions for the column "s_o"
3) I need only one obs for the column "px_last", which can be the last, as well as another (as well as the mean).
Apologise if date is in integers.
Any suggestion on how to avoid doing this manually?
Thank You
SG
Comment