Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Take the latest observation per fiscal-period

    Hi,

    I want to take (or mark) the latest forecast (variable= forecast_date) per fiscal-period (variable= fiscal_period). Also, the announcement date (variable= anndats) needs to be within 3 months of fiscal-period end (i.e. fiscal_period < anndats, and anndats - fiscal_period <=3 )

    Does anyone know how to do these? Thank you in advance!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str8 cusip long forecast_date double medest long(fiscal_period anndats)
    "87482X10" 19830  .07 19813 19849
    "87482X10" 19858  .13 19904 19941
    "87482X10" 19893  .13 19904 19941
    "87482X10" 19921  .13 19904 19941
    "87482X10" 19949  .26 19996 20031
    "87482X10" 19984  .25 19996 20031
    "87482X10" 20012  .25 19996 20031
    "87482X10" 20047  .17 20088 20118
    "87482X10" 20075  .17 20088 20118
    "87482X10" 20103  .17 20088 20118
    "87482X10" 20138  .17 20178 20208
    "87482X10" 20166  .18 20178 20208
    "87482X10" 20194  .18 20178 20208
    "87482X10" 20222  .22 20269 20299
    "87482X10" 20257  .22 20269 20299
    "87482X10" 20285  .22 20269 20299
    "87482X10" 20320  .23 20361 20389
    "87482X10" 20348  .24 20361 20389
    "87482X10" 20376  .24 20361 20389
    "87482X10" 20411  .26 20453 20479
    "87482X10" 20439  .26 20453 20479
    "87482X10" 20467  .27 20453 20479
    "87482X10" 20502  .28 20544 20571
    "87482X10" 20530  .28 20544 20571
    "87482X10" 20558  .28 20544 20571
    "87482X10" 20593  .31 20635 20662
    "87482X10" 20621  .31 20635 20662
    "87482X10" 20649  .31 20635 20662
    "87482X10" 20684   .3 20727     .
    "26878510" 19830  .15 19813 19850
    "26878510" 19858  .23 19904 19941
    "26878510" 19893  .23 19904 19941
    "26878510" 19921  .21 19904 19941
    "26878510" 19949  .26 19996 20031
    "26878510" 19984  .25 19996 20031
    "26878510" 20012  .23 19996 20031
    "26878510" 20047  .27 20088 20137
    "26878510" 20075  .27 20088 20137
    "26878510" 20103  .27 20088 20137
    "26878510" 20138  .17 20178 20207
    "26878510" 20166  .16 20178 20207
    "26878510" 20194  .16 20178 20207
    "26878510" 20222  .15 20269 20298
    "26878510" 20257  .15 20269 20298
    "26878510" 20285  .14 20269 20298
    "26878510" 20320   .2 20361 20389
    "26878510" 20348  .19 20361 20389
    "26878510" 20376  .19 20361 20389
    "26878510" 20411  .23 20453 20502
    "26878510" 20439  .23 20453 20502
    "26878510" 20467  .21 20453 20502
    "26878510" 20502  -.1 20544 20578
    "26878510" 20530 -.08 20544 20578
    "26878510" 20558 -.07 20544 20578
    "26878510" 20593  .16 20635 20669
    "26878510" 20621  .19 20635 20669
    "26878510" 20649   .2 20635 20669
    "26878510" 20684  .21 20727 20753
    "26878510" 20712  .21 20727 20753
    "26878510" 20747   .2 20727 20753
    "26878510" 20775   .2 20819 20879
    "26878510" 20803   .2 20819 20879
    "26878510" 20838   .2 20819 20879
    "26878510" 20866  .19 20819 20879
    "26878510" 20894 -.09 20909 20942
    "26878510" 20929 -.11 20909 20942
    "26878510" 20957  -.1 21000 21033
    "26878510" 20985  -.1 21000 21033
    "26878510" 21020 -.11 21000 21033
    "26878510" 21048 -.13 21092 21124
    "26878510" 21076 -.12 21092 21124
    "26878510" 21111 -.12 21092 21124
    "26878510" 21139 -.11 21184 21243
    "26878510" 21167 -.11 21184 21243
    "26878510" 21202  -.1 21184 21243
    "26878510" 21230 -.11 21184 21243
    "26878510" 21258 -.07 21274 21312
    "26878510" 21293 -.06 21274 21312
    "26878510" 21321 -.02 21365 21405
    "26878510" 21349 -.01 21365 21405
    "26878510" 21384    0 21365 21405
    "26878510" 21412    0 21457 21495
    "26878510" 21447 -.01 21457 21495
    "26878510" 21475 -.02 21457 21495
    "26878510" 21503 -.03 21549     .
    "26878510" 21538 -.07 21549     .
    "26878510" 21566  -.1 21549     .
    "26878510" 21594 -.13 21549     .
    "02504D10" 19858   .2 19813 19848
    "02504D10" 19893  .29 19904 19939
    "02504D10" 19921  .29 19904 19939
    "02504D10" 19949  .29 19996 20030
    "02504D10" 19984  .29 19996 20030
    "02504D10" 20012  .29 19996 20030
    "02504D10" 20047   .3 20088 20128
    "02504D10" 20075   .3 20088 20128
    "02504D10" 20103   .3 20088 20128
    "02504D10" 20138   .3 20178 20212
    "02504D10" 20166   .3 20178 20212
    "02504D10" 20194   .3 20178 20212
    end
    format %d forecast_date
    format %d fiscal_period
    format %d anndats
    Last edited by Helen Chang; 23 Apr 2019, 14:45.

  • #2
    I want to take (or mark) the latest forecast (variable= forecast_date) per fiscal-period (variable= fiscal_period).
    Code:
    by cusip fiscal_period (forecast_date), sort: ///
        gen latest_forecast_date = forecast_date[_N]
    format latest_forecast_date %td
    Also, the announcement date (variable= anndats) needs to be within 3 months of fiscal-period end (i.e. fiscal_period < anndats, and anndats - fiscal_period <=3 )
    I don't understand what you want here. The variable anndats already exists and it either is or is not within 3 months of the fiscal period end. So I don't know what you mean when you say it "needs to be." It either is or isn't. Is there something you want to compute based on whether it is or not?

    Comment


    • #3
      Thanks for the code, Clyde!!

      Regarding the second question, I want to keep (or mark) only the observations if the announcement date (variable= anndats) is within 3 months of fiscal-period end (i.e. fiscal_period < anndats, and anndats - fiscal_period <=3 ).

      Comment

      Working...
      X