Announcement

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

  • #16
    Many thanks again for the support. The commands are working now. I have a few questions here.

    1) What is the following command exactly doing?
    rangestat (sum) deal, by(cusip) interval(Year -3 -1)
    2) Does the following drop observations which have a deal sum which is missing or one? If so, shouldn't it be also higher than one? Additionally, are only the observations with role = a dropped or also the ones with role = t?
    by obs_no (deal_sum), sort: drop if inrange(deal_sum[_N], 1, .)

    3) Regarding the previous command. It is very important that I only want to drop observations which are not a deal (deal = 0) and NOT observations which are a deal (deal = 1). I do not see any specification here that only observations are dropped which are not a deal.

    4) What is incorrect with the command I suggested. I'm just asking for future use.

    Comment


    • #17
      1) What is the following command exactly doing?
      rangestat (sum) deal, by(cusip) interval(Year -3 -1)
      For each observation in the data set, it examines all other observations in the data set which have the same cusip and have a Year that is between 3 years before and 1 year earlier and then adds up the values of deal in those observations. Since deal is always either 0 or 1, this is equivalent to counting the number of observations with deal = 1.

      2) Does the following drop observations which have a deal sum which is missing or one? If so, shouldn't it be also higher than one? Additionally, are only the observations with role = a dropped or also the ones with role = t?
      by obs_no (deal_sum), sort: drop if inrange(deal_sum[_N], 1, .)
      It drops all those observations where the number of deals found by -rangestat- is 1 or greater. See -help inrange()- for a full explanation of how -inrange()- works. It does not drop those where this result is missing. This command makes no reference to the role, so both role = a and role = t will be dropped.

      3) Regarding the previous command. It is very important that I only want to drop observations which are not a deal (deal = 0) and NOT observations which are a deal (deal = 1). I do not see any specification here that only observations are dropped which are not a deal.
      I did not understand that to be the case. You are correct that the command does not do that. So it should be
      Code:
      by obs_no (deal_sum), sort: drop if inrange(deal_sum[_N], 1, .) & deal == 0
      4) What is incorrect with the command I suggested. I'm just asking for future use.
      I don't know. Maybe nothing. It's a very long and convoluted approach, and even if it is entirely correct, if a couple of weeks from now you wanted to change the code to use with different parameters of the problem (maybe a 4 year window instead of 3, or something like that) doing so would be very difficult and time consuming. So even if the code has no errors and works fine, it is not a good approach to solving the problem. Honestly, I didn't even read more than the first couple of lines of it before deciding that it's just not a good approach and that something simpler, more transparent, and more maintainable would be better than tweaking that.

      Comment

      Working...
      X