I would like to count the number of consecutive increase (up to 8, 8 being the max) of a variable (WC01551A) by group (stock). The counter must stop if the variable does not increase, remain the same if WC01551A remains the same. I have monthly data but need to count by quarter. That means I need to count increases of current WC01551A relative to lag 3, lag 6, lag 9, lag 12 .... lag 24 (and not lag 1, 2 ..., 8). My dataset is "tsset stock date".
This is the data I have:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double stock float date double WC01551A 1 432 67551 1 433 67551 1 434 67551 1 435 67551 1 436 67551 1 437 67551 1 438 67551 1 439 67551 1 440 67551 1 441 67551 1 442 67551 1 443 67551 1 444 78628 1 445 78628 1 446 78628 1 447 78628 1 448 78628 1 449 78628 1 450 78628 1 451 78628 1 452 78628 1 453 78628 1 454 78628 1 455 78628 1 456 98529 1 457 98529 1 458 98529 1 459 10544 1 460 10544 1 461 10544 1 462 77984 1 463 77984 1 464 77984 1 465 113198.66666666666 1 466 113198.66666666666 1 467 113198.66666666666 1 468 115613 1 469 115613 1 470 115613 1 471 120917 1 472 120917 1 473 120917 1 474 125834 1 475 125834 1 476 125834 1 477 123878 1 478 123878 1 479 123878 1 480 125781 1 481 125781 1 482 125781 1 483 125171 1 484 125171 1 485 125171 1 486 126020 1 487 126020 1 488 126020 1 489 124120 1 490 124120 1 491 124120 1 492 112027 1 493 112027 1 494 112027 1 495 100045 1 496 100045 1 497 100045 1 498 96925 1 499 96925 1 500 96925 1 501 100791 1 502 100791 1 503 100791 1 504 105362 1 505 105362 1 506 105362 1 507 99465 1 508 99465 1 509 99465 1 510 113825 1 511 113825 1 512 113825 1 513 106833 1 514 106833 1 515 106833 1 516 97815 1 517 97815 1 518 97815 1 519 95295 1 520 95295 1 521 95295 1 522 81733 1 523 81733 1 524 81733 1 525 88348 1 526 88348 1 527 88348 1 528 88348 1 529 101084 1 530 101084 1 531 101084 end format %tm date label values stock unit_id label def unit_id 1 "130062", modify
0 Response to Count the number of consecutive increase of a variable by group
Post a Comment