Hi all,
I have a dataset with an id that it is not unique and would like to do a reshape long. Now, dataex cannot be used since the columns are too much.
So I report here a sample also of the column which expand til 2015 with the same shape (four quarters each year):
I HAVE TRIED THE FOLLOWING
without success since of course idproduct does not uniquely identify each observation. Also the creation of a unique identifier like
seems to me unfair since there is no unique identifier actually in my variables.
How can I reshape the data long quarterly in this case?
Many thanks for the help!!!
I have a dataset with an id that it is not unique and would like to do a reshape long. Now, dataex cannot be used since the columns are too much.
So I report here a sample also of the column which expand til 2015 with the same shape (four quarters each year):
Code:
input double idproduct long(salesmnf2004Q1 salesmnf2004Q2 salesmnf2004Q3 salesmnf2004Q4 salesmnf2005Q1 salesmnf2005Q2 salesmnf2005Q3 salesmnf2005Q4) 1 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 3 244 342 5966 9472 629 0 0 0 3 339329 324989 426281 283110 24306 0 0 0 3 36 0 0 0 0 0 0 0 3 68188 37382 28741 18225 533 0 0 0 3 124 0 0 0 0 0 0 0 3 246552 152074 182095 174629 14832 0 0 0 3 227 174 0 0 0 0 0 0 3 7659 5855 1930 1788 122 0 0 0 3 56 11 0 0 0 0 0 0 3 37894 40017 51435 42338 4143 0 0 0 3 0 272 282 235 0 0 0 0 3 252 180 0 0 0 0 0 0 3 27520 30257 23095 13895 771 0 0 0 3 528 1009 588 805 121 0 0 0 3 108352 127944 123135 112263 31098 0 0 0 3 16695 8061 9343 9790 2425 0 0 0 3 87 0 0 0 0 0 0 0 3 1263 1197 1253 1383 41 0 0 0 3 128 63 370 195 0 0 0 0 3 234 0 329 338 40 0 0 0 3 1678 628 307 203 9 0 0 0 3 780 535 948 0 0 0 0 0 3 662 634 533 591 0 0 0 0 3 0 0 31 0 0 0 0 0 3 88284 216147 70070 62426 9134 0 0 0 3 138154 148580 163605 133421 7557 0 0 0 3 104 172 558 415 9 0 0 0 3 31695 33263 19931 9743 492 0 0 0 3 572550 605649 784501 664120 53733 0 0 0 4 0 0 0 0 0 0 0 0 5 16911 26506 16190 16224 19013 25620 32119 50588 5 15687 19615 12401 12910 15598 12736 13489 12955 5 0 0 0 0 0 0 0 0 5 6124 4219 4345 4317 4537 4846 5973 7038 5 76 0 0 0 0 0 0 110 5 3224 2896 2545 1539 2503 2319 3962 5368 5 0 0 0 0 0 0 0 0 5 244 247 230 212 261 204 125 534 5 0 0 0 0 0 0 0 0 6 29 54 29 0 5 43 14 31 7 175 0 0 0 0 0 0 0 7 175 0 0 0 0 0 0 0 7 175 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 9 386 302 172 340 649 2230 202 385 9 7334 6198 5362 6881 6297 3189 3342 3822 9 0 0 0 0 0 0 0 0 9 363775 361731 246456 265171 333133 336635 445020 404845 9 398457 292293 232842 252645 368193 308239 247530 257376 9 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 9 398457 292293 232842 252645 368193 308239 247530 257376 9 913 895 1109 1715 1898 1060 884 1407 9 0 0 0 0 0 0 0 0 9 278705 278967 223250 317347 331716 278549 269238 348433 9 2883 2478 2800 3450 2545 354 503 456 9 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 9 398457 292293 232842 252645 368193 308239 247530 257376 9 7334 6198 5362 6881 6297 3189 3342 3822 9 2883 2478 2800 3450 2545 354 503 456 9 7334 6198 5362 6881 6297 3189 3342 3822 9 278705 278967 223250 317347 331716 278549 269238 348433 9 308966 162855 74246 87758 220874 180348 384623 161786 9 152529 137185 130706 183804 14027 29956 37088 49404 9 82716 55264 35327 51997 53842 28729 26095 56379 9 2883 2478 2800 3450 2545 354 503 456 9 308966 162855 74246 87758 220874 180348 384623 161786 9 31757 16536 13854 14973 4774 2396 3008 4219 9 363775 361731 246456 265171 333133 336635 445020 404845 9 0 0 0 0 0 0 0 0 9 82716 55264 35327 51997 53842 28729 26095 56379 9 386 302 172 340 649 2230 202 385 9 2883 2478 2800 3450 2545 354 503 456 9 386 302 172 340 649 2230 202 385 9 363775 361731 246456 265171 333133 336635 445020 404845 9 7334 6198 5362 6881 6297 3189 3342 3822 9 913 895 1109 1715 1898 1060 884 1407 9 0 0 0 0 0 0 0 0 9 278705 278967 223250 317347 331716 278549 269238 348433 9 363775 361731 246456 265171 333133 336635 445020 404845 9 0 0 0 0 0 0 0 0 9 913 895 1109 1715 1898 1060 884 1407 9 308966 162855 74246 87758 220874 180348 384623 161786 9 308966 162855 74246 87758 220874 180348 384623 161786 9 5987 4611 4213 3631 1947 2438 3259 2532 9 0 0 0 0 0 0 0 0 9 386 302 172 340 649 2230 202 385 9 0 0 0 0 0 0 0 0 9 398457 292293 232842 252645 368193 308239 247530 257376 9 278705 278967 223250 317347 331716 278549 269238 348433 9 82716 55264 35327 51997 53842 28729 26095 56379
Code:
reshape long salesmnf, i(idproduct) j(quarter) string gen trimestre = quarterly(quarter, "YQ") format trimestre %tq gen Year = year(dofq(trimestre))
Code:
gen id_numeric = _n
How can I reshape the data long quarterly in this case?
Many thanks for the help!!!
Comment