Announcement

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

  • keep observations according to some criteria

    Hi again,

    I have some data that has firm ID (firm), Edate (event date), a dummy variable IsForecast, and a count variable ForecastNum, which can take value 0, 1, or 2. IsForecast indicate whether there is (at least 1) forecast, whereas ForecastNum count its actual number, so when IsForecast == 1, ForecastNum must be either 1 or 2, it can't be 0.

    For each firm, there is one or several event dates. For those firms with more than one event dates, I want to keep one event date with IsForecast and ForecastNum not be 0. The entry not necessarily occur first or last within each firm, so I don't know how to deal with it.

    Some event dates are missing, if that is the case, both IsForecast and ForecastNum will be 0. Some data here:

    Note: the instances of ForecastNum == 2 is not very common, so the example data generated by dataex does not show the instances where ForecastNum is 2.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double firm float(Edate IsForecast ForecastNum)
    150 21937 1 1
    153     . 0 0
    156 21934 0 0
    157 21930 0 0
    159 21937 1 1
    159 22020 0 0
    166 21853 0 0
    338     . 0 0
    400 22020 0 0
    400 21932 0 0
    403 21930 0 0
    408 22020 0 0
    411 21848 0 0
    415 22021 0 0
    419 22019 0 0
    420 22020 0 0
    420 21937 1 1
    422 21932 0 0
    423 21934 0 0
    423 22020 0 0
    428 21935 0 0
    428 22020 0 0
    430 22020 0 0
    430 21935 0 0
    488 22019 0 0
    501 22015 0 0
    509 21935 0 0
    509 22020 0 0
    516 21945 1 1
    516 22020 0 0
    517 21936 0 0
    517 22020 0 0
    519 22019 0 0
    520 22019 0 0
    526 22020 0 0
    526 21936 0 0
    528 21937 1 1
    534 22005 0 0
    536 22020 0 0
    536 21937 1 1
    544 21930 0 0
    545 22022 0 0
    546 21932 0 0
    546 22020 0 0
    547 21932 0 0
    553 21937 1 1
    554     . 0 0
    558 22020 0 0
    558 21932 0 0
    558 21853 0 0
    559 22020 0 0
    561 22020 0 0
    563 21918 0 0
    564 21937 1 1
    564 22020 0 0
    568     . 0 0
    576 22019 0 0
    582 21945 1 1
    584 22020 0 0
    584 21945 1 1
    590 21935 0 0
    592 22020 0 0
    596     . 0 0
    601     . 0 0
    606 21937 1 1
    606 22020 0 0
    607 22020 0 0
    607 21853 0 0
    610 22018 0 0
    610 21932 0 0
    612 21936 0 0
    612 22016 0 0
    615 21945 0 0
    615 22020 0 0
    617     . 0 0
    619 22014 0 0
    623 21935 0 0
    627     . 0 0
    629 21929 0 0
    629 22016 0 0
    630 22020 0 0
    631 22019 0 0
    632     . 0 0
    633 21935 0 0
    633 22020 0 0
    635 21937 1 1
    635 22019 0 0
    636 21937 1 1
    637 22020 0 0
    637 21935 0 0
    639 21945 1 1
    655 22019 0 0
    655 21936 0 0
    661 21917 0 0
    663 21935 0 0
    663 22020 0 0
    665     . 0 0
    669 22020 0 0
    669 21937 1 1
    670 22020 0 0
    end
    Thanks in advance for any help!

  • #2
    would it not be:

    keep if IsForecast==1 & ForecastNum==1

    or,

    keep if IsForecast==1 & ForecastNum>0 (will you give multiples if ForecastNum has values 1 or 2)

    Comment

    Working...
    X