Dear Stata Users,
I have the end of the fiscal year month (the dataset is monthly). My final goal is to construct a date variable that will have a fiscal year and fiscal quarter. First, I define a fiscal year:
Then, I want to label months (like 1st, 2nd, 3rd) in a fiscal year. My idea is to use something like this:
However, this code does not allocates month within the fiscal year. Can you, please help me with this issue.
\
I have the end of the fiscal year month (the dataset is monthly). My final goal is to construct a date variable that will have a fiscal year and fiscal quarter. First, I define a fiscal year:
Code:
bys permno: replace fyear = fyear - 1 if month(date)<fyr
Code:
{ if month == fyr { replace month = 1 } else if fyr<month { replace month =month- fyr } else if fyr>month { replace month =month + fyr } }
\
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date double fyear float month int mdate double fyr 54594 13695 1997 6 449 5 54594 13726 1997 7 450 5 54594 13573 1997 2 445 5 54594 13818 1997 10 453 5 54594 13604 1997 3 446 5 54594 13846 1997 11 454 5 54594 13879 1997 12 455 5 54594 13755 1997 8 451 5 54594 13634 1997 4 447 5 54594 13664 1997 5 448 5 54594 13545 1997 1 444 5 54594 13787 1997 9 452 5 54594 13969 1998 3 458 5 54594 14028 1998 5 460 5 54594 14244 1998 12 467 5 54594 14213 1998 11 466 5 54594 14060 1998 6 461 5 54594 14182 1998 10 465 5 54594 14152 1998 9 464 5 54594 14122 1998 8 463 5 54594 13999 1998 4 459 5 54594 13937 1998 2 457 5 54594 13909 1998 1 456 5 54594 14091 1998 7 462 5 54594 14487 1999 8 475 5 54594 14517 1999 9 476 5 54594 14425 1999 6 473 5 54594 14578 1999 11 478 5 54594 14455 1999 7 474 5 54594 14334 1999 3 470 5 54594 14609 1999 12 479 5 54594 14392 1999 5 472 5 54594 14273 1999 1 468 5 54594 14546 1999 10 477 5 54594 14364 1999 4 471 5 54594 14301 1999 2 469 5 54594 14669 2000 2 481 5 54594 14973 2000 12 491 5 54594 14853 2000 8 487 5 54594 14640 2000 1 480 5 54594 14882 2000 9 488 5 54594 14914 2000 10 489 5 54594 14822 2000 7 486 5 54594 14761 2000 5 484 5 54594 14728 2000 4 483 5 54594 14791 2000 6 485 5 54594 14944 2000 11 490 5 54594 14700 2000 3 482 5 54594 15187 2001 7 498 5 54594 15309 2001 11 502 5 54594 15155 2001 6 497 5 54594 15064 2001 3 494 5 54594 15279 2001 10 501 5 54594 15006 2001 1 492 5 54594 15034 2001 2 493 5 54594 15218 2001 8 499 5 54594 15126 2001 5 496 5 54594 15095 2001 4 495 5 54594 15246 2001 9 500 5 54594 15340 2001 12 503 5 54594 15427 2002 3 506 5 54594 15371 2002 1 504 5 54594 15460 2002 4 507 5 54594 15582 2002 8 511 5 54594 15705 2002 12 515 5 54594 15552 2002 7 510 5 54594 15491 2002 5 508 5 54594 15644 2002 10 513 5 54594 15613 2002 9 512 5 54594 15399 2002 2 505 5 54594 15519 2002 6 509 5 54594 15673 2002 11 514 5 54594 16037 2003 11 526 5 54594 15917 2003 7 522 5 54594 15736 2003 1 516 5 54594 15855 2003 5 520 5 54594 16070 2003 12 527 5 54594 15886 2003 6 521 5 54594 15764 2003 2 517 5 54594 15825 2003 4 519 5 54594 15978 2003 9 524 5 54594 16009 2003 10 525 5 54594 15795 2003 3 518 5 54594 15946 2003 8 523 5 50906 14244 1998 12 467 10 50906 14091 1998 7 462 10 50906 14028 1998 5 460 10 50906 13937 1998 2 457 10 50906 13909 1998 1 456 10 50906 13999 1998 4 459 10 50906 14213 1998 11 466 10 50906 14060 1998 6 461 10 50906 14152 1998 9 464 10 50906 14122 1998 8 463 10 50906 14182 1998 10 465 10 50906 13969 1998 3 458 10 50906 14455 1999 7 474 10 50906 14334 1999 3 470 10 50906 14392 1999 5 472 10 50906 14301 1999 2 469 10 end format %d date format %tm mdate
Comment