Dear All,
I am currently experiencing some difficulties in adding rows to my dataset. I would greatly appreciate it if you can give me any suggestions or advice.
Here is information on key variables in my dataset:
ch is the number of weeks the song charted
mweek_th is the week the song charted (week id)
id is song id
I want to add rows based on the value of ch. For example, song 1 first hit the chart in week 85 and had charted for 16 weeks. I want to add additional 15 rows with the value of mweek_th increasing by 1 as follows:
The rows highlighted in red are what I want to add to the existing dataset.
I have not been able to come up with an efficient solution for this. Any suggestion would be greatly appreciated. Thank you so much!
Anna
I am currently experiencing some difficulties in adding rows to my dataset. I would greatly appreciate it if you can give me any suggestions or advice.
Here is information on key variables in my dataset:
ch is the number of weeks the song charted
mweek_th is the week the song charted (week id)
id is song id
I want to add rows based on the value of ch. For example, song 1 first hit the chart in week 85 and had charted for 16 weeks. I want to add additional 15 rows with the value of mweek_th increasing by 1 as follows:
ch | mweek_th | id |
16 | 85 | 1 |
16 | 86 | 1 |
16 | 87 | 1 |
16 | 88 | 1 |
16 | 89 | 1 |
16 | 90 | 1 |
16 | 91 | 1 |
16 | 92 | 1 |
16 | 93 | 1 |
16 | 94 | 1 |
16 | 95 | 1 |
16 | 96 | 1 |
16 | 97 | 1 |
16 | 98 | 1 |
16 | 99 | 1 |
16 | 100 | 1 |
32 | 2134 | 2 |
32 | 2135 | 2 |
I have not been able to come up with an efficient solution for this. Any suggestion would be greatly appreciated. Thank you so much!
Anna
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte ch float(mweek_th id) 16 85 1 32 2134 2 39 2444 3 21 1993 4 45 1900 5 20 1965 6 14 2747 7 23 2909 8 1 433 9 end
Comment