Hi all,
Using a monthly panel dataset I'm trying to build a variable containing the average earnings of a worker over the last 12 months. There are workers with missing observations in my data so for those workers I would like to use the available information. For example, if in the last year the worker was observed for 10 months I want the average earnings over those months. Does anyone have an idea on how to generate this variable? I'm including data for a worker so you can see what I mean. I basically want what I would obtain if I were to use the average function in excel. I need something like rowtotal but for columns.
Thanks for your help.
Using a monthly panel dataset I'm trying to build a variable containing the average earnings of a worker over the last 12 months. There are workers with missing observations in my data so for those workers I would like to use the available information. For example, if in the last year the worker was observed for 10 months I want the average earnings over those months. Does anyone have an idea on how to generate this variable? I'm including data for a worker so you can see what I mean. I basically want what I would obtain if I were to use the average function in excel. I need something like rowtotal but for columns.
Thanks for your help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float cal_month double renta_all float avg_earning_prev_12m_2 514 124670 . 515 249340 . 516 228790 . 517 287700 . 518 401410 . 519 313730 . 520 275370 . 521 205500 . 522 221940 . 523 197280 . 524 267150 . 525 216460 . 526 256190 249111.67 527 221940 260071.67 528 219200 257788.33 529 267150 256989.17 530 256190 255276.67 531 302770 243175 532 228790 242261.67 533 226050 238380 534 184950 240092.5 535 306880 237010 536 234270 246143.33 537 206870 243403.33 538 219200 242604.17 539 246600 239521.67 540 210980 241576.67 541 213720 240891.67 542 150700 236439.17 543 . 227648.33 544 16440 . 545 . . 546 . . 547 . . 548 . . 549 . . 550 . . 551 . . 552 . . 553 . . 554 . . 555 . . 556 97270 . 557 197280 . 558 80830 . 559 . . 560 . . 561 . . 562 . . 563 . . 564 . . 565 . . 566 . . 567 1370 . 568 . . 569 . . 570 . . 571 . . 572 . . 573 . . 574 . . 575 . . 576 . . 577 . . 578 . . 579 . . 580 . . 581 . . 582 . . 583 363050 . 584 374010 . 585 374010 . 586 374010 . 587 49320 . 588 . . 589 . . 590 . . 591 . . 592 . . 593 . . 594 . . 595 . . 596 . . 597 . . 598 . . 599 . . 600 . . 601 . . 602 . . 603 . . 604 . . 605 . . 606 . . 607 . . 608 . . 609 . . 610 . . 611 . . 612 . . 613 172620 . end format %tm cal_month
Comment